Wednesday, September 26, 2012

SpringMVC JSR 303 Validator: Certain Fields Need to All Be Populated Or All Empty

This validator is useful when you have an object that certain fields are grouped together in a way that they all need to be populated or all empty.

You supply the field names on the validation annotation, which then during validation uses reflection to get the values from the objects to make sure they are all populated or all empty.  If the validation fails, the error message is attached to each field so that each field could display an error message.

The only drawback to this validator is that it will only work with one group of fields.

To the Code:

No comments:

Post a Comment