I have multiple validation annotation on each filed of my bean, but I want to display only first failed message for each field in my spring MVC application where I am using JSR 303. Currently, it is evaluating all the constraints and displaying all the messages messages for each field. When a filed is empty, I dont want to evaluate its min and max constraint.
I have tried with groups, but it is not working as expected and more over I need to invoke the validator explicitly something like validator.validate() which I want to avoid.
IS there any alternative to achieve this by over writing some validation classes?
I have at least 3 constraints for each field and maximum 5. Displaying all theses messages for each field is not at all looking good. I am suing spring 4.x and hibernate 4.x
The way to go is via groups and group sequences. That's the only portable feature which ensures an validation order and termination of validation if a constraint within a group fails. Can you not assign the constraints in your bean to appropriate groups and then redefine the default groups sequence for the bean itself? See also http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-default-group-class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With