以下是我的JSF
表单电子邮件地址部分:
(Registration.xhtml
)
<p:inputText id="email" required="true" label="Email" size="20" value="#{registrationBean.email}">
<f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)"/>
<f:validator id="uniqueEmailValidator"/>
</p:inputText>
<h:message for="email"/>
这是我的验证员类:
@FacesValidator("uniqueEmailValidator")
public class UniqueEmailValidator implements Validator {
@Override
public void validate(FacesContext fc, UIComponent uic, Object value) throws ValidatorException {
if (value == null) {
return;
}
String email = (String) value;
CustomerService cService = new CustomerService();
if (!cService.exists(email)) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "mail is already in use.", "error"));
}
}
}
运行应用程序时出现此错误:
/Registration.xhtml @49,73 <f:validator> A validator id was not specified. Typically the validator id is set in the constructor ValidateHandler(ValidatorConfig)
答案 0 :(得分:1)
在你的f:validator标签中,更改&#34; id&#34;到&#34; validatorId&#34;
<f:validator validatorId="uniqueEmailValidator"/>