You create a validation group by setting the ValidationGroup property to the same name (a string) for all the controls you want to group. You can assign any name to a validation group, but you must use the same name for all members of the group.
Use the ValidationGroup property to specify the name of the validation group for which the Button control causes validation when it posts back to the server. This property has an effect only when the value of the CausesValidation property is set to true .
Group constraints are optional linear constraints that group assets together and enforce bounds on the group weights (see Group Constraints).
The @Valid annotation will tell spring to go and validate the data passed into the controller by checking to see that the integer numberBetweenOneAndTen is between 1 and 10 inclusive because of those min and max annotations.
The standard java @Valid
annotation doesn't support groups. However, Spring now includes an @Validated
annotation which does the same job as @Valid
, but allows you to specify which groups to use in the validation:
@ModelAttribute("myCandidate") @Validated(UpdateGroup.class) Candidate myCandidate
Note that this annotation is only available in Spring 3.1 and newer.
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