在 JSF2 中使用 bean 验证 (JSR 303) - Primefaces 应用程序 [英] Using bean validation (JSR 303) in JSF2 - Primefaces application
问题描述
我正在尝试将使用休眠验证器的 bean 验证集成到我的 Web 应用程序中:
-tomcat 7 上的 Hibernate-spring-jsf2-primefaces3
我在 Netbeans 的类路径中添加了以下 jar 文件:hibernate-validator.jar 和 validation-api.jar.
I'm trying to integrate bean validation using hibernate validator to my web application :
- Hibernate-spring-jsf2-primefaces3 on tomcat 7
I added following jar files : hibernate-validator.jar and validation-api.jar to my classpath in Netbeans.
在 pojo 类中,我为 Size 添加了注释:
In the pojo class, I added annotation for Size :
@Size(min=4, message="Min 4 chars!")
private String name;
在我写的 .xhtml 页面中:
In the .xhtml page I wrote :
<p:inputText title="name" id="name" value="#{myBean.user.name}"></p:inputText>
<p:message for="name" />
运行我的应用程序并在名称字段中输入少于 4 个字符后,我看不到任何消息,处理继续并将数据保存到数据库.在我看到的日志输出中:
after running my application and typing less than 4 chars in the name field I see no message and the processing continue and save data to database. In the log output I saw :
14 juin 2012 14:55:03 org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate shouldAddEnclosingValidator
ATTENTION: Bean validation is not available on the classpath, thus the BeanValidator will not be added for the component org.primefaces.component.inputtext.InputText@1f3fd22
14 juin 2012 14:55:04 javax.faces.component._ExternalSpecifications isBeanValidationAvailable
INFO: MyFaces Bean Validation support disabled
我想知道是否需要设置任何配置,或者是否需要添加任何 jar 文件.
I want to know if there is any config I have to set, or any jar file I have to add.
推荐答案
已解决,
我必须将所需的 jar 文件:jboss-logging-3.1.0.CR2.jar 从 hibernate-validator zip 文件添加到 lib 目录.
我认为 log4j 足以记录日志,但我错了.
Solved,
I had to add required jar file : jboss-logging-3.1.0.CR2.jar from hibernate-validator zip file to the lib directory.
I thought log4j was sufficient for logging but I was wrong.
这篇关于在 JSF2 中使用 bean 验证 (JSR 303) - Primefaces 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!