使用Bean验证(JSR 303)的JSF2 - Primefaces应用 [英] Using bean validation (JSR 303) in JSF2 - Primefaces application

查看:224
本文介绍了使用Bean验证(JSR 303)的JSF2 - Primefaces应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Hibernate验证到我的web应用程序整合Bean验证:结果
- 在Tomcat 7的Hibernate弹簧JSF2-primefaces3
结果
我添加以下jar文件:休眠-validator.jar和验证-api.jar文件到我的Netbeans中的类路径

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类,我添加注释的尺寸:

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-测井3.1.0.CR2.jar从休眠状态,验证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.

这篇关于使用Bean验证(JSR 303)的JSF2 - Primefaces应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆