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,当对其他字段的验证失败时,我需要从验证器中清除输入文本。我尝试过使用setSubmittedValue(“”或setValue(“”),但它不起作用 我之所以要这样做是因为该字段是一个captcha字段,如果对其他字段的验证失败,页面将使用新的captcha代码呈现,我希望输入字段为空 表格: <h:form id="form"> <h:inputText id="otherfieldid" required="true" requiredMessage=

当对其他字段的验证失败时,我需要从验证器中清除输入文本。我尝试过使用
setSubmittedValue(“”
setValue(“”
),但它不起作用

我之所以要这样做是因为该字段是一个captcha字段,如果对其他字段的验证失败,页面将使用新的captcha代码呈现,我希望输入字段为空

表格:

<h:form id="form">
   <h:inputText id="otherfieldid" required="true"
        requiredMessage="Please enter"
        validator="#{bean.validateA}"
        validatorMessage="Validation fails" />

    <h:inputText id="fieldid" required="true"
        requiredMessage="Please enter"
        validator="#{bean.validateB}"
        validatorMessage="Validation fails" />
</h:form>

输入字段的
value=“#{yourBeam.field}
绑定在哪里?如果验证失败,应该可以将Bean中的此字段设置为null…

我忘了添加我尝试过的内容和绑定,两者都不起作用。
@ManagedBean
@ViewScoped
public Bean {
    public void validateA(FacesContext context,
                UIComponent componentToValidate,
                Object value)
                throws ValidatorException {
        /* validation codes */
    }

    public void validateB(FacesContext context,
                UIComponent componentToValidate,
                Object value)
                throws ValidatorException {

        HtmlInputText ht = 
            (HtmlInputText) context.getViewRoot().findComponent(":form:otherfieldid");

        if (ht != null) {           
            if (ht.getValidatorMessage() != null 
                    || !"".equals(ht.getValidatorMessage())) {              
                ((HtmlInputText) componentToValidate).setSubmittedValue("");
                return;
            }
        }
        /* validation codes */
    }
}