• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Handling Messages (v1.2.9)

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble with figuring out how to handle messages in Struts.

For the sake of experimentation, here is what I have in my action method:



and in my jsp file:



When I execute the action, the only thing that shows up is the text "Messages present".

I know my message resources file is being found because I am using Struts Validation and the validation messages show up under the html:errors when I enter an error in the form. This also tells me that Struts is finding the tag library okay as well. And yes, I have messages.saved, messages.test, and messages.amg all defined in the message resources file.

What is the proper way to handle adding error and informational messages? And what might my problem be?

Note: I am using tiles. Could this be complicating matters?

Thanks,

Scott

Update: I also tried using message literals rather than keys to the message resources bundle. Same result.

i.e.:


[ October 31, 2007: Message edited by: Scott Arnold ]

[ October 31, 2007: Message edited by: Scott Arnold ]

[ October 31, 2007: Message edited by: Scott Arnold ]
[ October 31, 2007: Message edited by: Scott Arnold ]
 
Scott Arnold
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As an additional diagnostic, I tried doing a saveMessages(request.getSession(),messages) with no change in results.

Why isn't there better information online for how to make use of Struts ActionMessages? And why isn't it more intuitive? I'm really starting to get aggravated. Using ActionMessages should be easy and clearly explained online in many places. Yet it is apparently not. Now I have to either abandon it or start digging into Struts source code to figure out what should be a simple part of the framework. Ridiculous.
 
Scott Arnold
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some additional diagnostics -- I tried simply adding the messages to the request manually using my own key as follows:



And in the jsp:



This time the messages showed up when used with html:errors but not under html:messages.
 
Scott Arnold
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I've finally figured it out I think. I was missing the include for the bean tag library. I don't suppose there is a log file somewhere that would have indicated that there were unrecognized tags?

Best I can tell now that I can actually get it to work and play with it, it looks like first parameter for the add method of the ActionMessages class ties the error to a particular property (a property typically being a single field on a form, but could probably be anything). Therefore, if the message doesn't need to be tied to a particular field, some global constant should be used, which is provided through the constant ActionMessages.GLOBAL_MESSAGE. From there, whether it gets recognized as a message message or an error message is determined by whether you call saveMessages or saveErrors.

Therefore, to save a generic informational message, the proper code would be as follows:



And in the jsp, they could be displayed using:



The code is kind of excessive. It would be better if they had a method such as addMessage(ActionMessage actionMessage) and addMessage(String property, ActionMessage actionMessage). Then you could just call addMessage(new ActionMessage("some.key")).

To anyone who is confused about how the above example would be done for errors, it would look like this (assuming I am correct now):



with the jsp like this:



Hope this thread helps someone someday...
[ October 31, 2007: Message edited by: Scott Arnold ]
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic