【问题标题】:JSF 1.2 dynamically adding custom validatorJSF 1.2 动态添加自定义验证器
【发布时间】:2012-05-08 14:45:58
【问题描述】:

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

谢谢

【问题讨论】:

  • 您可以尝试创建自定义验证器来装饰您需要的验证器。基于属性您可以选择验证器并在组件上运行它。

标签: jsf lifecycle jsf-1.2 customvalidator


【解决方案1】:

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

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-09-29
  • 2012-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-05
  • 2017-12-06
  • 1970-01-01
  • 2017-08-13
相关资源
最近更新 更多