|
|
Parameterized Error messages
I'm using spring portlet mvc for developing my portal. I have a requirement wherein i need to pass some dynamic string messages to actually formatted error string.
Here is my errors.properties file.Code:
member.invited=An email has sent to {0} to join the group.
In the controller, i'm doing this to display proper error message when the condition is met.Code:
errors.rejectValue(quot;successMsgquot;, quot;member.invitedquot;, new String[]{email} , quot;quot;);
IN the above code email = email of the person invited which is a string object.
But on the screen, it shows the error message like quot;An email has sent to {0} to join the group.quot;
It won't substitute email in the place of {0}.
What am i doing wrong? How to make this working?
Any help in this regard is highly appreciated.
Thank you.
The problem may be in how you're displaying the error messages in your view (JSP, etc). Can you provide the code for this?
I'm displaying the error message using following code in jsp:Code:
lt;form:errors path=quot;successMsgquot; /gt;
Anything wrong there? PLease correct.
Can somebody answer my query? It's bit urgent.
Thank you.
Try using the following :
Code:
lt;c ut value=quot;${status.errorMessage}quot; /gt;
under the spring:bind tag for the property the error message is displayed.
For example :
Code:
lt;spring:bind path=quot;login.userIdquot;gt;
lt;c ut value=quot;${status.errorMessage}quot; /gt;
lt;input type=quot;textquot; name=quot;userIdquot;value='lt;c ut value=quot;${status.value}quot;/gt;'gt;
lt;/spring:bindgt;
In the above code, userId is the property and since the error message is binded to the property , if you enter invalid values in userId text field, then whatever the error message is returned from validator, will be displayed on the page .
I hope this solution helps you out.
Cheers,
Sushant
Thanks Sushant for the reply.
Actually my successMsg is not bind to any form variable. It occurrs on special conditions in which case, i call bindErrors.rejectValue in the controller which causes this error message to be displayed.
How to display such error messages in jsp?
Please help.
Can somebody answer my query. It's bit urgent. |
|