I want to do a little custom validation using JSR-303 javax.validation .
I have a field. And if a certain value is entered in this field, I want to require that several other fields are not null .
I'm trying to figure it out. Not sure what I would call this to help find an explanation.
Any help would be greatly appreciated. I am new to this.
I'm currently thinking about user restrictions. But I'm not sure how to check the value of the dependent field from the annotation. Basically, I'm not sure how to access the panel object from the annotation.
public class StatusValidator implements ConstraintValidator<NotNull, String> { @Override public void initialize(NotNull constraintAnnotation) {} @Override public boolean isValid(String value, ConstraintValidatorContext context) { if ("Canceled".equals(panel.status.getValue())) { if (value != null) { return true; } } else { return false; } } }
This is panel.status.getValue(); gives me problems .. not sure how to do this.
java validation bean-validation
Eric Feb 14 '12 at 21:30 2012-02-14 21:30
source share