Hibernate 为什么jsf无法在Integer属性类型中使用jsf validator属性调用validate方法,而出现另一条错误消息?

Hibernate 为什么jsf无法在Integer属性类型中使用jsf validator属性调用validate方法,而出现另一条错误消息?,hibernate,jsf-2,richfaces,seam,Hibernate,Jsf 2,Richfaces,Seam,我想验证一个只包含数字的简单字段。value属性绑定到seam entity Home的一个实例 代码 <h:inputText id="text" value="#{personHome.intance.age}" validator="#{bean.validateAge}"> <a4j:support event="onblur" reRender="text, errorAge" /> </h:inputText> <rich:m

我想验证一个只包含数字的简单字段。value属性绑定到seam entity Home的一个实例

代码

<h:inputText id="text" value="#{personHome.intance.age}" 
    validator="#{bean.validateAge}">
   <a4j:support event="onblur" reRender="text, errorAge" />
</h:inputText>
<rich:message id="errorAge" for="text" styleClass="errors"/>
是hibernate验证程序吗?
有人能告诉我我在这里错过了什么吗

您还没有发布任何关于validateAge方法的信息,它遵循什么

public void validate(FacesContext context, UIComponent toValidate, Object value)
签名。

你可能有一条缝

<s:validateAll> 


标记输入文本周围的内容。它们触发bean字段上的hibernate验证程序。您可以删除

<s:validate> 

标记在这种情况下将调用validate方法,或者您可以创建自定义的hibernate验证器(@Age),将其放在Age bean字段中,并从输入文本中删除validator属性

@BypassInterceptors
@Name("yourAgeValidator")
@org.jboss.seam.annotations.faces.Validator
public class YourAgeValidator

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    ....
}


<h:inputText id="text" value="#{personHome.intance.age}"  validator="yourAgeValidator">
更新:

还有第三个选项:要创建自定义jsf验证器(而不是验证器方法),请向seam注册它并将其应用于输入文本

@BypassInterceptors
@Name("yourAgeValidator")
@org.jboss.seam.annotations.faces.Validator
public class YourAgeValidator

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    ....
}


<h:inputText id="text" value="#{personHome.intance.age}"  validator="yourAgeValidator">
@旁路拦截器
@姓名(“yourAgeValidator”)
@org.jboss.seam.annotations.faces.Validator
公共类YourAgeValidator
@凌驾
公共void验证(FacesContext上下文、UIComponent组件、对象值)引发Validator异常{
....
}

的确如此。我试过另一个输入文本,它的值是模型中的字符串,它工作得很好。但是,当在模型中对有界于Integer属性的值使用时,会出现消息。我将尝试使用此消息。如果对我有用,我会通知你的谢谢你的回答
@BypassInterceptors
@Name("yourAgeValidator")
@org.jboss.seam.annotations.faces.Validator
public class YourAgeValidator

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    ....
}


<h:inputText id="text" value="#{personHome.intance.age}"  validator="yourAgeValidator">