• 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

Checking for an ActionMessage in the JSP

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the latest version of Struts. Using code similar to below I can add an ActionMessage into the request:

ActionMessage message = new ActionMessage("some.key");
ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, message ); saveErrors(req,messages);

Now there is sample code that will print out all the ActionMessages in the JSP, but I don't need that.

Is there a way to check if the ActionMessage "some.key" (above) is in the request ??
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, but not w/o iterating through the ActionMessages stored in the request key 'ActionMessages.GLOBAL_MESSAGE' using scriptlets...ugh. if you only want to see if messages exist, you can call the ActionMessages.isEmty(). otherwise, iterate and do ActionMessage.getKey() and compare to "some.key"...very ugly indeed.

since you are storing the messages in the action anyway, why not add a request attribute using the message key as the key. ex. after adding the message, do request.setAttribute("some.key","1");

in your jsp, you can check the existence of the request attribute. the only problem here is if you are using JSTL, your keys need to be "some_key" (so you can do <c:if test="${not empty requestScope.some_key}"> </c:if>. otherwise, you'll just do <%if(request.getAttribute("some.key") != null){%> <% } %>
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"jc98789"

Please once again read the naming policy. I think we have pretty clearly spelled out what we are looking for there as far as our naming conventions are concerned, as evidenced by the fact that the rest of the people who remain members of this site have no problem following it. You have been warned on numerous occasions by several moderators and given ample opportunity to comply.
[ June 01, 2005: Message edited by: Jason Menard ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic