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 */
}
}