Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JSF验证器中传递第二个值?_Jsf_Jsf 2 - Fatal编程技术网

如何在JSF验证器中传递第二个值?

如何在JSF验证器中传递第二个值?,jsf,jsf-2,Jsf,Jsf 2,我在编辑页面和验证器中有一个简单的JSF输入表单,用于检查重复值: <td>Name</td> <td> <h:outputText value="#{ud.name}" rendered="#{not DCProfileTabGeneralController.editable}" /> <h:inputText id="dcname" value="#{ud.name}" rendere

我在编辑页面和验证器中有一个简单的JSF输入表单,用于检查重复值:

<td>Name</td>
<td>
    <h:outputText value="#{ud.name}"
                  rendered="#{not DCProfileTabGeneralController.editable}" />
    <h:inputText id="dcname" value="#{ud.name}" rendered="#{DCProfileTabGeneralController.editable}"
                 validator="#{ValidatorDatacenterController.validateDatacenterName}" autocomplete="off">
        <f:ajax event="blur" render="dcnamevalidator" />
    </h:inputText>
    <h:message id="dcnamevalidator" for="dcname" />
</td>

public void validateDatacenterName(FacesContext context, UIComponent component, Object value){
....
}
名称
public void validateDatacenterName(FacesContext上下文、UIComponent组件、对象值){
....
}
我很感兴趣,是否有任何可能的方法发送第二个值,用于验证过程?

。将一个添加到inputtext并在验证器中检索它

<h:inputText id="dcname".....
<f:attribute name="param" value="myparam" /> 
</h:inputText>

可以从EL获取值。祝您好运

您可以添加postValidate事件来验证多个字段,如

<f:event listener="#{bean.validationMethod}" type="postValidate" />

如果验证失败,请调用FacesContext renderResponse方法跳过模型更新。

从实际代码示例来看,似乎没有理由发送其他值。最好解释一下您的功能需求,以获得更好的指导,或者您向验证器发送第二个参数的动机。我喜欢在这里使用f:ajax,所以我不需要找到组件和其他东西。此ofc需要比RequestScope更长的作用域
<f:event listener="#{bean.validationMethod}" type="postValidate" />
FacesContext fc = FacesContext.getCurrentInstance(); 
UIComponent components = event.getComponent();
UIInput param1 = (UIInput) components.findComponent("param1");
UIInput param2 = (UIInput) components.findComponent("param2");