I use the JSR303 Bean Validation to check the form input.
@NotBlank
@Size(min = 4, max = 30)
private String name;
@NotBlank
@Size(max = 100)
@Email
private
Yes Bean Validation supports this feature. It is called validation groups and group sequences. Groups are simple marker interfaces, for example you could create the two interfaces First and Second and change your code to something like this:
@NotBlank(groups = First.class)
@Size(min = 4, max = 30, groups = Second.class)
private String name;
Then you can define a group sequence:
@GroupSequence({ First.class, Second.class})
interface All {
}
Get hold of the Validator and call validator.validate(myObject, All.class)
It's all in the documentation.