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
2010-09-11 16:42:25
A:
I use JSR-303 Bean Validation (see example here). Simply annotate the fields that you need to validate.
James Earl Douglas
2010-09-12 04:16:24
did you read the question?
seanizer
2010-09-12 07:34:41
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
2010-09-12 16:45:52