views:

23

answers:

2

What's the preferred approach for validating that at least one of fieldA, fieldB, or fieldC is valid using a Spring 3 validator? In other words, any 2 of the fields can be invalid, as long as the third is not.

A: 

This thread poses almost the same question. The solution there is to add the following to validation-rules.xml:

<validator name="requiredif" 
    classname="org.springmodules.validation.commons.Fi eldChecks"
    method="validateRequiredIf" 
    methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.springframework.validation.Errors, org.apache.commons.validator.Validator"
    msg="errors.required">
</validator> 
Bozho
A: 

I use JSR-303 Bean Validation (see example here). Simply annotate the fields that you need to validate.

James Earl Douglas
did you read the question?
seanizer
Indeed I did, and Spring's 303 support is my "preferred approach for validating". My example doesn't cover this specific use case, but that's why it's an example and not a solution to this particular question.
James Earl Douglas