'Bean Validation @NotNull, @NotBlank and @NotEmpty does not work in JSF+Tomcat
I am using Hibernate Validation annotations in my JSF managed bean. When I use @NotNull, @NotBlank or @NotEmpty they doesn't seem to be triggered in any way.
@NotBlank(message = "{name.required}")
public String name;
View:
<h:outputLabel value="Name:" />
<h:inputText id="name" value="#{person.name}" size="20" />
<h:message for="name" style="color:red" />
How is this caused and how can I solve it?
Solution 1:[1]
I had a similar issue and i was able to overcome the problem by including the below three jars in web-inf lib. Just add the hibernate validator jar and the required jars as provided in the zip file:
hibernate-validator-4.3.0.Final.jarjboss-logging-3.1.0.CR2.jarvalidation-api-1.0.0.GA.jar
Solution 2:[2]
add
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
in web.xml
and add
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.23.Final</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13</version>
</dependency>
in pom.xml
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xaerxess |
| Solution 2 |
