Reputation: 9063
I have a problem with Hibernate Validator 3.1.0.GA not looking up custom validation messages in the property file ValidationMessages.properties.
To illustrate the problem, I created a small example project, which you can get through git:
git clone https://bitbucket.org/sstein/validation-example.git
After you got the source tree, you can test the problem by running the unit tests I created using:
mvn test
There are 3 test cases and validateDescriptionTest(com.example.MyClassTest) is failing with:
expected:<[Description must be between 1 and 10 characters long.]> but was:<[{descriptionMsg}]>
I also added a test case verifying that the resource bundle is accessible by unit tests and this works.
Does anyone know why this one is failing?
PS: I completely rewrote my initial question adding the example so that you can try on your own.
Upvotes: 1
Views: 1699
Reputation: 9063
So the solution is simple and was found by Hardy Ferentschik of Hibernate:
In Hibernate Validator 3.1.0.GA, the bundle must be called ValidatorMessages.properties and NOT ValidationMessages.properties.
Upvotes: 1
Reputation: 4022
The final location of ValidationMessages.properties shuold be in WEB-INF/classes. How it gets there depends on the build system you are using and how you configure it. In NetBeans IDE, when I create a web application, I can just put ValidationMessages.properties into the default Java package.
In case you are using Maven as a build tool, put the properties into the /src/main/resources directory, this way Maven will copy it into WEB-INF/classes.
To make sure that the properties file is in place, open the .war file as a ZIP and just take a look. Another way to tell is just by checking if JSF picks up the validator messages inside.
For JSR-303 messages like @Size, the above properties key should be correct.
Upvotes: 2