This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DISPLAYING MESSAGES USING html:messages TAG

 
Abhishek Dwaraki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}
 
Abhishek Dwaraki
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic