In my MVC spring check, the order of my error messages changes randomly, I would like the messages to be in the same order as on the page.
My AccountForm.java class looks like this:
@NotNull(message = "Account name cannot be empty.")
@Size(min=3, max=50, message="Account name must be between 3 and 50 characters long.")
private String accountName;
@NotNull(message = "Company name cannot be empty.")
@Size(min=3, max=50, message="Company name must be between 3 and 50 characters long.")
private String companyName;
And I also add some user errors in my controller:
public ModelAndView create(@Valid AccountForm accountForm, BindingResult bindingResult) {
ModelAndView mav = new ModelAndView("accounts/new");
mav.addObject("errors", bindingResult.getAllErrors());
mav.addObject("accountForm", accountForm);
if (!bindingResult.hasErrors()) {
if(accountService.findByAccountName(accountForm.getAccountName()) != null) {
bindingResult.addError(new ObjectError("accountName", "Account name is already is use"));
}
..
..
}
if(bindingResult.hasErrors() {
return mav;
}
..
When I click submit on the form, the order of the posts continues to change.
I make mistakes in my view using:
<#list errors as error>
<li>${error.defaultMessage}</li>
</#list>
Can this be fixed?
source
share