Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess Spring MVC BindingResult from within a View
    primarykey
    data
    text
    <p>I'm looking for a way to access a <code>BindingResult</code> from within the view (in my case a JSP page).</p> <p>I have the following controller method:</p> <pre><code>@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; } </code></pre> <p>When executing this, the <code>RegistrationData</code> get's populated and the errors are stored in the <code>BindingResult</code>. So far, so good. However, I do have to add the <code>BindingResult</code> manually into the <code>ModelAndView</code> for it to become visible within the View.</p> <p>Is there a way to <strong>automatically</strong> add the <code>BindingResult</code> into the model? I already tried adjusting the method signature to</p> <pre><code>public ModelAndView doRegisterAccept( @Valid @ModelAttribute("registrationData") RegistrationData registrationData, @ModelAttribute("bindingResult") BindingResult bindingResult ) { </code></pre> <p>where I was hoping - as any other parameter - the <code>BindingResult</code> would get added into the model under the key <code>bindingResult</code>but unfortunately that's not working.</p> <p>So, any ideas?</p> <h2>Addition</h2> <p>I just found that the results indeed get published using the key</p> <pre><code>org.springframework.validation.BindingResult.&lt;NAME_OF_MODEL_ATTRIBUTE&gt; </code></pre> <p>so I suppose just adding it under the plain name is not encouraged by the Spring guys?!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload