Using bean validation (JSR 303) in JSF2 - Primefaces application

坚强是说给别人听的谎言 提交于 2019-12-13 19:22:04

问题


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.

In the pojo class, I added annotation for Size :

@Size(min=4, message="Min 4 chars!")
private String name;

In the .xhtml page I wrote :

<p:inputText title="name" id="name" value="#{myBean.user.name}"></p:inputText>
<p:message for="name" />

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

I want to know if there is any config I have to set, or any jar file I have to add.


回答1:


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.




回答2:


This question has been answered before.

You need a Java EE container if you want to use bean validation. Tomcat is only a servlet container and therefore you need additional libraries.

Not getting JSR303 annotations to work with Tomcat 7



来源:https://stackoverflow.com/questions/11035882/using-bean-validation-jsr-303-in-jsf2-primefaces-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!