Spring Order Validation Annotations

I want to ask if it is possible to explicitly specify the check order in Spring. I mean, I have this command object:

public class UserData { @NotBlank private String newPassword; @NotBlank private String confirmPassword; @Email(applyIf="email is not blank") @NotBlank private String email; @NotBlank private String firstName = ""; private String middleName = ""; @NotBlank private String lastName = ""; // getters/setters } 

and I display my error messages at the top of the page as follows:

 <spring:hasBindErrors name="${userData}"> <ul class="errors"> <c:forEach items="${errors.allErrors}" var="error"> <li><spring:message message="${error}"/></li> </c:forEach> </ul> </spring:hasBindErrors> 

The problem is that my error messages are displayed in the following order:

 * Fill you last name. * Fill you password. * Fill your emailaddress. * Fill you password again. * Select your gender. * Fill your first name. 

This is no coincidence, because this order is maintained every time. This is not an alphabet, nor any other order ... I'm really stuck. Can anyone help?

+4
source share
2 answers

SpringModules is a dead project, it is no longer supported. If you need JSR-303 validation support in Spring, I suggest using the reference implementation, Hibernate Validator, and connecting it like this .

Having said that, this may not solve your problem, but at least you will use modern libraries, which will make it easier to fix them.

+3
source

I found that using @GroupSequence works, although it does not seem to be the right solution.

For a quick study, see http://www.jroller.com/eyallupu/entry/jsr_303_beans_validation_using .

+2
source

Source: https://habr.com/ru/post/1316134/


All Articles