0
votes

After a couple hours of Google and a couple of tutorials I'm beat... It's not the fact that I'm getting errors that can give me hints on what the problem is, it's the complete lack of them that's driving me mad!

The following code works, just not as it should! The annotations for checking that the input is not null or lesser then 3 character long just never runs. Nor are they giving any kind of error when the project is being deployed or when the name variable is being written to.

public class testBean
{
    @NotNull
    @Size(min=3)
    private String name;
}

public void test()
{
    System.out.println(name);
}

And the input form:

<h:form>
        <h:inputText value="#{testBean.name}" />
    <h:commandButton value="Send" action="#{testBean.test()}" />
</h:form>

My guess is that it's tomcat that's causing the problems, although I am fairly sure I've imported all the necessary libraries. Same goes for the IDE I'm using, Eclipse.

2
Did you read the section on validation in this article? laliluna.de/articles/jsf-2-evaluation-test.htmlmaple_shaft
Further, I have never gotten @NotNull to work on a managed bean property. I believe that if the property is null it never sends its value to be validated.maple_shaft
Unfortunately that article didn't do much :S Still wont execute the annotations.David
Please note that those annotations are not related to JSF. They are part of JSR303 bean validation. Tomcat7 doesn't ship with it out the box. What JSR303 libs exactly have you included and where?BalusC
@Balus: That's true, I should have been more specific. As for the libs, I've inluded the "validation-api-1.0.0.GA.jar" both in the "WEB-INF/lib" folder and also the "apache-tomcat-7/lib" folder.David

2 Answers

5
votes

As for the libs, I've inluded the "validation-api-1.0.0.GA.jar" both in the "WEB-INF/lib" folder and also the "apache-tomcat-7/lib" folder.

You've installed only the API, not the implementation. The API is an abstract contract so that you can declare/use it in your code and have the freedom in choosing the implementation. The implementation contains the concrete code and does the real work. You need to install the impl as well. The JSR-303 reference implemtation is the Hibernate Validator. The download details are here. Currently the latest final is 4.1.0. It contains the hibernate-validator-4.1.0.Final.jar file which is the real implementation. Drop it in Webapp/WEB-INF/lib. It does not necessarily need to be in Tomcat7/lib, I'd remove the API from there as well to prevent future classpath collisions.

1
votes

I had the same kind of problem, and search for a while, in my case, using hibernate-validator-4.2.0.Final.jar, I was lacking slf4j-api-1.6.4.jar. The problem is that hibernate validator does not crash but does NOT tell it is not working ....