title: Handling password confirmations on spring-mvc
body: <p>I am doing an user crud in spring-mvc.</p>
  
  <p>My model has the following properties:</p>
  
  <pre><code>private Long id;
  private String password;
  private String username;
  private Collection&lt;Authority&gt; myAuthorities;
  private boolean isAccountNonExpired;
  private boolean isAccountNonLocked;
  private boolean isCredentialsNonExpired;
  private boolean isEnabled;
  </code></pre>
  
  <p>I solved how to show the <code>Authority</code> class in this <a href="https://stackoverflow.com/questions/3498193/spring-mvc-3-0-crud-with-checkboxes-issue">question</a>.</p>
  
  <p>Now I am willing my form to be able to have a second password field to confirm that the user typed the password correctly.</p>
  
  <p>I don't want to add a <code>confirmPassword</code> property to the model, so my question is how to fix this the best way possible.</p>
  
  <p>Edit:</p>
  
  <p>Everything is working with axtavt's answer but I am missing a way to validate.
  I have the following method in my controller, but even though I place a <code>@Validate</code>
  <code>ApplicationUserFormValidator</code> isn't called.</p>
  
  <pre><code>    @RequestMapping(method = RequestMethod.POST)
   public ModelAndView create(Model model,
     @Valid @ModelAttribute ApplicationUserForm applicationUserFrom,
     BindingResult result) {
    ModelAndView modelAndView = new ModelAndView();
  
    if (result.hasErrors()) {
     modelAndView.setViewName(USER_CREATE_FORM);
    } else {
     modelAndView.setViewName(REDIRECT_TO_USER_LIST);
     modelAndView.addObject(USER_FORM_MESSAGE, USER_FORM_ADD_SUCCESSFUL);
     applicationUserService.save(applicationUserFrom.getUser);
    }
  
    return modelAndView;
   }
  </code></pre>