| Author |
DISPLAYING MESSAGES USING html:messages TAG
|
Abhishek Dwaraki
Ranch Hand
Joined: Feb 13, 2006
Posts: 44
|
|
I need to display messages using the html:messages tag in my JSP. The problem here is that the messages are not getting displayed due to some problem. I have coded the ActionMessages Object.add() directly in the Action class itself and not put it inside any error condition like it is normally done in the ActionForm's validate method... Inspite of just trying to display a message right outside, as soon as the Action Class is mapped into, there is no message being displayed... Someone plz advice on this... Any help will be appreciated and thanks in advance... The config file is alright... Will just put in the code snippets of the jsp and the Action Class.. This is from the Action Class : ActionMessages message2 = new ActionMessages(); message2.add("This is a test message", new ActionMessage("testmessages.try","This is to test the ActionMessages Class")); This is from the jsp : <li> <html:messages id="message"> <bean:write name="message" /> </html:messages> </li>
|
Regards,
Abhishek Dwaraki
Dept of Electrical and Comp Engg
University of Massachusetts, Amherst
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
Change message2.add("This is a test message", new ActionMessage("testmessages.try","This is to test the ActionMessages Class")); to message2.add("message", new ActionMessage("testmessages.try","This is to test the ActionMessages Class")); The id attribute of your <html:messages> tag must match the first parameter of the ActionMessages.add method. Also, make sure there's an entry in your ApplicationResources.properties file for testmessages.try={0}
|
Merrill
Consultant, Sima Solutions
|
 |
Abhishek Dwaraki
Ranch Hand
Joined: Feb 13, 2006
Posts: 44
|
|
|
Thanks for the help Merrill... But even after changing that parameter the messages are not being displayed.. I'm not able to figure out why this is happening... I also have the corresponding message entry in my ApplicationResources.properties file... Plz do advice on any other pitfalls that are there... I'm stuch with this and unable to go ahead 'cos I'm not able to display any messages in the JSP...
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
Sorry, my mistake. It's the property attribute, not the id attribute of the <html:messages> tag that must match the first parameter of the ActionMessages.add method. If the message is a global message, the first parameter should be ActionMessages.GLOBAL_MESSAGE. To display global messages, just leave the property attribute blank. So, change the code in your action class to: message2.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("testmessages.try","This is to test the ActionMessages Class")); and it should work. Here is a link that explains all this. Look for the section entitled Displaying Messages.
|
 |
Liju Cherian
Ranch Hand
Joined: Mar 17, 2006
Posts: 44
|
|
Hi ,
ActionMessages message2 = new ActionMessages(); message2.add("This is a test message", new ActionMessage("testmessages.try","This is to test the ActionMessages Class"));
After the above code in your action class are u saving the ActionMessages object to request ..?? If u r not, try adding this statement before forwarding to the jsp file. saveMessages(request, message2); Hope this helps. Liju [ March 30, 2006: Message edited by: Liju Cherian ]
|
"What's in a name? That which we call a rose by any other name would smell just as sweet."<br />(William Shakespeare, Romeo and Juliet, Act II, Scene II)
|
 |
 |
|
|
subject: DISPLAYING MESSAGES USING html:messages TAG
|
|
|