I am doing an user crud in spring-mvc.
My model has the following properties:
private Long id;
private String password;
private String username;
private Collection<Authority> myAuthorities;
private boolean isAccountNonExpired;
private boolean isAccountNonLocked;
private boolean isCredentialsNonExpired;
private boolean isEnabled;
I solved how to show the Authority
class in this question.
Now I am willing my form to be able to have a second password field to confirm that the user typed the password correctly.
I don't want to add a confirmPassword
property to the model, so my question is how to fix this the best way possible.
Edit:
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 @Validate
ApplicationUserFormValidator
isn't called.
@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;
}