Reputation: 1389
I couldn't get Java Bean Validation (JSR-303) working. It doesn't give any error and processes the action method. I put one character to "name" inputText, it accepts and process() method gets executed (Size annotation doesn't apply).
When I put one character I expect the My.Process() method to not to be executed, am I not right? Is there any configuration I overlook to get validation working?
In WEB-INF/lib dir of my project I have validation-api-1.0.0.GA.jar, hibernate-validator-4.2.0.Final.jar.
App Server: Tomcat 7.0.25 (inside Tomcat's Lib folder I have myfaces-api-2.1.5.jar and myfaces-impl-2.1.5.jar).
IDE: Eclipse Helios SR2
I get the message "INFO: MyFaces Bean Validation support disabled" from console, but I have the jars as I specified.
Bean
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.validation.constraints.Size;
@ManagedBean(name="my")
@RequestScoped
public class MyBean implements Serializable {
@Size(min=3, message="ERROR")
private String name;
public String process() {...}
...getters, setters, etc...
}
JSF form
<h:form>
<h:messages />
<h:inputText value="#{my.name}" />
<h:commandButton value="Save" action="#{my.process}" />
</h:form>
I also tried:
@NotEmpty, @NotBlank,
@org.hibernate.validator.constraints.Length(min=3, message="ERROR")
but they don't work too.
Upvotes: 1
Views: 7110
Reputation: 5366
Thanks for this! FYI, maven coordinates for bean-validator:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>bean-validator</artifactId>
<version>3.0-JBoss-4.0.2_03</version>
</dependency>
Upvotes: 1
Reputation: 1389
I'd like to write a possible problem.
When I had have this variable
private String Name;
Validation didn't work because the getter and setters are like this
private String getName(){}
So I renamed Name to
private String name;
and it started to validate :)
Probably that was the problem.
Upvotes: 3