【问题标题】:Can we pass parameters to the JSF Validator我们可以将参数传递给 JSF 验证器吗
【发布时间】:2015-09-23 23:38:30
【问题描述】:

我们可以将参数值传递给 xhtml 页面中的 JSF Validator。 例如<h:inputText value='#{myvalue}' validator='#{validator.method(param)}' /> 或者有什么方法可以这样做。 因为我有一个数据表,其中有两列包含字段dealerType (selectOneMenu) 和dealerNumber(inputText),其中dealerNumber 文本强度验证基于以前的dealerType。

【问题讨论】:

  • 是的,如有必要,使用<f:attribute name="..." value="#{...}"/> 并绑定到您感兴趣的另一个组件。基本上,您正在寻找跨字段验证标准 (example)。

标签: validation jsf jsf-2


【解决方案1】:

您可以像这样在 inputText 的验证器方法中访问 selectOneMenu 的值:

public void validate(FacesContext context, UIComponent component, Object value) 
        throws ValidatorException {
    UIInput input = (UIInput) context.getViewRoot().findComponent("selectOneMenuID");
    String str = (String) input.getSubmittedValue();
    // now do the validation based on 'str'
}

【讨论】:

  • 无法获得唯一的 selectOneMenuID,因为它在 dataTable 中,JSF 在 selectOneMenuID 中添加 rowIndex
猜你喜欢
  • 2012-01-01
  • 2015-10-26
  • 1970-01-01
  • 2013-06-11
  • 2010-12-13
  • 2023-04-01
  • 2015-09-23
  • 1970-01-01
  • 2013-01-05
相关资源
最近更新 更多