Hi,
I have a form
<form:form commandName="command" method="post">
<form:errors path="property"/>
// some fields
</form:form>
And a MultiActionController
Command command = new Command();
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
for (Validator validator: getValidators())
if(validator.supports(command.getClass()))
validator.validate(command, binder.getBindingResult());
if(binder.getBindingResult().hasErrors())
// What to put here in order to show error message in <form:errors path="property"/>
Question just above. I have used
return new ModelAndView()
.addObject(binder.getBindingResult().getModel())
.addObject("command", command);
But does not work fine. When the form is shown again (after a failure) command properties is shown but error messages not
correct answer: instead of
return new ModelAndView()
.addObject(binder.getBindingResult().getModel())
.addObject("command", command);
I have to call
return new ModelAndView()
.addAllObjects(binder.getBindingResult().getModel());
Notice addAllObjects. Now it works fine!
regards,