I am looking for a way to access BindingResultfrom a view (in my case a JSP page).
I have the following controller method:
@RequestMapping(value="/register/accept.html",method=RequestMethod.POST)
public ModelAndView doRegisterAccept(
@Valid @ModelAttribute("registrationData") RegistrationData registrationData,
BindingResult bindingResult
) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("bindingResultXXX", bindingResult);
modelAndView.setViewName("users/registration/register");
return modelAndView;
}
When doing this, it is RegistrationDatapopulated and errors are saved in BindingResult. So far, so good. However, I need to add BindingResultmanually in ModelAndViewso that it becomes visible in the view.
Is there a way to automatically add BindingResultto the model? I already tried setting the method signature to
public ModelAndView doRegisterAccept(
@Valid @ModelAttribute("registrationData") RegistrationData registrationData,
@ModelAttribute("bindingResult") BindingResult bindingResult
) {
where I was hoping, since any other parameter BindingResultwill be added to the model under the key BindingResult, but, unfortunately, this does not work.
So any ideas?
Adding
I just found that the results are really published using the key
org.springframework.validation.BindingResult.<NAME_OF_MODEL_ATTRIBUTE>
, Spring?!