Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been doing the same thing from past 1.5 days and finally i found a solution of that.</p> <p>May be it sounds a bit crazy but its a working solution. :)</p> <pre><code>@Size(min = 1, max = 50, message = "Email size should be between 1 and 50") </code></pre> <p>Now remove <code>message = "Email size should be between 1 and 50"</code> from validation tag.</p> <p>After doing this your annotation will be like this.</p> <pre><code>@Size(min = 1, max = 50) </code></pre> <p>Now at controller side debug the method which is being called upon when submitting the form. Below is my method which is receiving the request when user hits submit.</p> <pre><code>public static ModelAndView processCustomerLoginRequest(IUserService userService, LoginForm loginForm, HttpServletRequest request, HttpSession session, BindingResult result, String viewType, Map&lt;String, LoginForm&gt; model) </code></pre> <p>Now place a debug point at very first line of the method and debug the argument "result".</p> <pre><code>BindingResult result </code></pre> <p>While dubugging you will find a string like this in codes array.</p> <pre><code>Size.loginForm.loginId </code></pre> <p>Now define this string in your properties file and a message against that string. Compile and execute. That message will be displayed whenever that annotation wouldn't be validated. </p> <pre><code>Size.loginForm.loginId=email shouldn't be empty. </code></pre> <p>Basically spring makes its own string as key to its property file message. In above key:</p> <ul> <li><code>Size(@Size)</code> = validation annotation name</li> <li><code>loginForm</code> = my class name</li> <li><code>loginId</code> = property name in <code>loginForm</code> class.</li> </ul> <p>The beauty of this method is it also runs fine while you will be using Spring Internationalization. It automatically switches the messages file as language changes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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