• 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

adding ActionMessages direct from JSP ?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm wondering if there is any way to add an ActionMessage directly from a JSP (as opposed to in the action). Is there any tag based solution to this (I'm not using scriptlets) ?

I tried writing a custom tag solution myself e.g. :



[in handler....]

ActionMessage newMessage = new ActionMessage("my.key.here");
ActionMessages messages = (ActionMessages)pageContext.getRequest().getAttribute(Globals.MESSAGE_KEY);
messages.add("message", newMessage);

[...]

This was throwing an exception at messages.add(), not sure if its because I was adding a message with no value, or if it just can't be done from here.

The key value I was adding was not being looked up in the resource file (not sure if this happens on saveMessages in the action class).

Thanks in advance for any help.

John.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are a few suggestions:


1- There may or may not be an existing ActionMessages object in the request, so your messages variable may be null. Just instantiate a new one if it's null.

2- When you've added your message to the ActionMessages object, put it in request scope with Globals.MESSAGE_KEY as the key. This isn't necessary if the object was already there, but it is necessary of you're instatiating a new one.
[ January 26, 2006: Message edited by: Merrill Higginson ]
 
John Stein
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
d'oh ! can't see the wood for the trees scenario!

I was so busy worrying about the underlying complexities of ActionErrors, I didn't check whether the object was already in scope.

Works a charm. Thanks for your help.

Jock.
[ January 27, 2006: Message edited by: John Stein ]
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic