• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DISPLAYING MESSAGES USING html:messages TAG

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
ice is for people that are not already cool. Chill with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic