0

如果我正确理解 JSF 生命周期,它会在应用请求阶段注册验证器。这是否意味着我无法将 addValidator 调用到我在处理请求事件阶段调用的 decode() 方法中的组件对象句柄?如果是这样,是否有任何其他方法可以根据组件的属性值动态添加自定义验证器?

谢谢

4

1 回答 1

0

我希望应该工作类似于..

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);
}  }
于 2012-05-09T11:10:43.060 回答