JSR 303 Validation Messages Fairytale

#validator
 data-srcset

Have you ever had a need to change the name and/or directory for ValidationMessages.properties
No? Lucky you!

By default you should place the ValidationMessages.properties file in your project classpath root, and if you don’t like it’s name (as I don’t) or would like to organize all messages in a separate directory (as I like), than you can face a really interesting challenge.

For me, the biggest problem in solving this enigma was that there was no example to copy/paste from (I love to copy/paste), or any kind of tutorial on this subject, so the simple task to put ValidationMessages into „messages“ directory and name it „validation_messages.properties“ turned into real nightmare. 
I could not sleep for days, I stopped eating and lost weight, my family abandoned me, my kids didn’t know me anymore, I lost the flat, house with a pool and tennis courts. 
To put it simple I lost everything, even my cat left me. But I did not lose hope! 
One morning, waking up in my brand new cardboard box, sobering from to much puddle water, it came… the car from the left side and hit me.

No, no, no, I’m just kidding…. … it was the idea. 
I ran to the closest mobile store, everyone left maybe because i smelled to much, who knows, and unnoticed, I downloaded Apache BVal source code not to the iPad, but Alcatel 7 inch smart phone dual core, 700×600 resolution with … who cares… unzipped it and 2 years later… [download the sources link] … 
I’m posting the whole blown method to the „ValidationMessages“ problem not from the iPad, + simple maven project where everything is put together so you can just simply copy and taste the joy from pasting it to your IDE.

private Validator getValidator(ResourceBundle messages) {
  Configuration builder = Validation.byDefaultProvider().configure();

  builder.messageInterpolator(new  DefaultMessageInterpolator(messages));

  return builder.buildValidatorFactory().getValidator();
}
Back

Increase your competitive advantage.

We will direct you in the right direction!

Contact us