简体   繁体   中英

Dynamic Error messages in Spring MVC3 Validation using hibernate

I want to be able to use a value from one form field (let's say name), if available, in the error message of another form field (lets say email).
For example: I want the error message for the email field to be like:
"Hi "+name+", please enter a valid email address."

Besides, I would also like to be able to customize error messages based on the time of the day/year, or based on other error messages. But I've not been able to do this so far; I get this error:

The value for annotation attribute NotEmpty.message must be a constant expression

Any suggestions on how this can be done?

Its due to you are using name variable in error message.
for doing this you can code at jsp page.
cutomize this by using if-else condition 
that particular error than print the given message like:
<c:if test="${success=='n'}">
      <b>put dynamic test here </b>
     <form:errors path="*"/>
</c:if>

where success is set at your controller like:

map.put("success", "n");

regards
Om

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM