我正在尝试使用<rich:beanValidator />验证rich:calendar中的非空值输入,但我无法验证空值输入。
例如,在我的constraits.xml文件中,我验证了日历的getter:
<getter name="dateOfBirth">
<constraint annotation="javax.validation.constraints.Past"/> (works fine)
<constraint annotation="javax.validation.constraints.NotNull" /> (not work)
<constraint annotation="org.hibernate.validator.constraints.NotEmpty"/> (not work)
</getter>最后两个约束不起作用是因为"DateTime“数据类型不能识别它们吗?(据我所知,第一个用于数值,第二个用于字符串)。
date time数据类型有这样的限制吗?我是否可以使用xml文件中为非空输入编写的约束来进行验证?
我被迫在xhtml中使用required="true“对rich:calendar (如果我使用hibernate验证器)进行这种验证(不是null)?
如果你有一个想法,请帮助我。
问候你,Mircea
发布于 2009-12-01 18:55:03
@NotNull:带批注的元素不能为null。接受任何类型。
你检查过它是否真的为空了吗?因为它可能已经设置为new Date()。此外,尝试使用注释,而不是constraints.xml (它可能是be验证器中的一个错误)
无论如何,required="true"似乎是一个很好的解决方案。
发布于 2009-12-04 15:31:57
JSF不验证空字段。但是,JSF2可以选择验证null,以便与bean验证框架兼容。
https://stackoverflow.com/questions/1825329
复制相似问题