title: Spring mvc form error not comng on jsp
body: <p>I am trying to validate a login form. Upon clicking login button, the control comes to my controller class and with the help of BindingResult i also came to know that my field has errors, but i am unable to show the error back on my jsp page. I have tried rejectValue method , but my jsp page throws exception that property is not readable e.t.c</p>
  
  <p>Here is my model class.</p>
  
  <pre><code>public class UserBean
  {
    @NotEmpty
    private String username;
    @NotEmpty
    private String password;
  
    public String getPassword()
    {
      return this.password;
    }
  
    public String getUsername()
    {
      return this.username;
    }
  
    public void setUsername(String username)
    {
      this.username = username;
    }
  
    public void setPassword(String password)
    {
      this.password = password;
    }  
  }
  </code></pre>
  
  <p>Here is my JSP page.</p>
  
  <pre><code>&lt;form:form method="POST" modelAttribute="login-entity"
      action="process-login.html"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="username"&gt;username:&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="username" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:errors path="username" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="password"&gt;password:&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="password" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:errors path="password" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="2"&gt;&lt;input type="submit" value="Login" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>and here is my controller class.</p>
  
  <pre><code>@RequestMapping(value = "/process-login", method = RequestMethod.POST)
    public ModelAndView processLogin(@Valid UserBean loginModel,BindingResult bindingResult, Model model)
    {
      if(bindingResult.hasErrors())
      {
        ModelAndView errorView = new ModelAndView("loginpage");
        bindingResult.rejectValue("username","invalid username");
        bindingResult.rejectValue("password","invalid password");
        errorView.addObject("login-entity", bindingResult.getModel());
        return errorView;
      }
      return new ModelAndView("redirect:/some_other_page","","");
    }
  </code></pre>
  
  <p>Upon debugging, my final error view object contains this thing.</p>
  
  <pre><code>ModelAndView: reference to view with name 'loginpage'; model is {login-entity={userBean=UserBean [userId=0, username=, password=], org.springframework.validation.BindingResult.userBean=org.springframework.validation.BeanPropertyBindingResult: 4 errors
  Field error in object 'userBean' on field 'username': rejected value []; codes [NotEmpty.userBean.username,NotEmpty.username,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBean.username,username]; arguments []; default message [username]]; default message [may not be empty]
  Field error in object 'userBean' on field 'password': rejected value []; codes [NotEmpty.userBean.password,NotEmpty.password,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userBean.password,password]; arguments []; default message [password]]; default message [may not be empty]
  Field error in object 'userBean' on field 'username': rejected value []; codes [invalid username.userBean.username,invalid username.username,invalid username.java.lang.String,invalid username]; arguments []; default message [null]
  </code></pre>
  
  <p>Can someone please help? I think i am missing some very fundamental thing.</p>