Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Validation Annotations Order

I want to ask is it possible to set explicitly the validation 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 on top of the page like this:

<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 no matter what 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.

It is not random, because this order is preserved every time. It is not alphabetical, or any other order... I am really stuck. Can someone help please?

like image 852
Petar Tahchiev Avatar asked Jul 19 '10 08:07

Petar Tahchiev


2 Answers

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

Having said that, this may not fix your problem, but at least you'll be using up-to-date libraries, likely making it easier to fix.

like image 166
skaffman Avatar answered Oct 21 '22 14:10

skaffman


I've found that using @GroupSequence works, though it doesn't feel like a proper solution.

See http://www.jroller.com/eyallupu/entry/jsr_303_beans_validation_using for a quick tutorial.

like image 2
adamcohenrose Avatar answered Oct 21 '22 12:10

adamcohenrose