1

我根据 JSF 2 规范注册了一个验证器:

@FacesValidator(value = "emailValidator")
public class EmailValidator implements Validator {..}

用法 :

<h:inputText value=#{bean.email}>
<f:validator id="emailValidator" />
</h:inputText>

我得到这个例外:

javax.servlet.ServletException: /contact.xhtml @21,130 <f:validator> A validator id was not specified. Typically the validator id is set in the constructor ValidateHandler(ValidatorConfig)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
myapp.FilterLogout.doFilter(FilterLogout.java:83)

那是一个错误吗?

4

1 回答 1

4

试试这个

@FacesValidator(value="emailValidator")
public class EmailValidator implements Validator {
 @override
     public void validate(FacesContext context, UIComponent component,
        Object value) throws ValidatorException {
     }
 }

在 xhtml 中,你有

           <h:inputText value=#{bean.email}>
             <f:validator validatorId="emailValidator" />
           </h:inputText>
于 2012-09-21T09:51:00.180 回答