If I understand the JSF lifecycle correctly, it registers the Validators during Apply Request phase. Does that mean I cannot call addValidator to the Component object handle I have inside my decode() method that gets called during Process Request Events phase? If so, is there any other way of dynamically adding custom Validators based on component's attribute value?
Thanks
What I hope should work is similar to..
public class ValidatorWrapper implements Validator {
private DoubleRangeValidator dbRangeValidator;
private LongRangeValidator lRangeValidator;
private String requiredValidatorType;/*An attribute to choose the type of validator*/
public ValidatorWrapper(){
dbRangeValidator = new DoubleRangeValidator(10.01, 20.99);lRangeValidator = new LongRangeValidator(10, 20);
}
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
if("LONG".equalsIgnoreCase(requiredValidatorType))
lRangeValidator.validate(context, component, value);
else if("DBL".equalsIgnoreCase(requiredValidatorType))
dbRangeValidator.validate(context, component, value);
} }