1
votes

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.

2

2 Answers

2
votes

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.

0
votes

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