Note that there are some explanatory texts on larger screens.

plurals
  1. POJSR-303 validation with custom message
    text
    copied!<p>I'm using Spring 3.0.5-RELEASE, with JSR-303 style validation and Hibernate validator 4.1.0-Final. My model class looks something like this:</p> <pre><code>public class Model { @Max(value=10,message="give a lower value") Integer n; } </code></pre> <p>And this is passed as request param in a spring mvc servlet with binding. So the request would look something like this:</p> <p><a href="http://localhost:8080/path?n=10" rel="nofollow">http://localhost:8080/path?n=10</a></p> <p>What I want is to be able to customize the error message when there is a type mismatch exception, e.g. </p> <p><a href="http://localhost:8080/path?n=somestring" rel="nofollow">http://localhost:8080/path?n=somestring</a></p> <p>Which results in a very long default message that I want to replace. </p> <p>I've tried just about every configuration described on the web and none of them seem to work. Does someone know what the right configuration is?</p> <p>Specifically, what do I need in my mvc-servlet.xml? What do I need in my messages.properties file? Does the message.properties file have a magic name so that hibernate-validator will find it?</p> <p>I've used the following in my mvc-servlet.xml without success:</p> <pre><code>&lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource" p:basename="messages" /&gt; </code></pre> <p>And a messages.properties file at src/main/resources (and also at src/main/webapp/WEB-INF)...</p> <p>I've tried all sorts of combinations in messages.properties even for doing simple override of say @NotEmpty messages and even that doesn't work for me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload