Meaningless Drivel is fun!*
The moose likes Struts and the fly likes ActionMessages causing me great distress Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionMessages causing me great distress" Watch "ActionMessages causing me great distress" New topic
Author

ActionMessages causing me great distress

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi all-

I'm trying to distinguish between ActionErrors and ActionMessages but it's not working:
The problem is that when I have an error, it's being displayed twice,
as both an error AND a message
but my messages are not being displayed at all.

(my pages use <html:errors/> and
<logic:messagesPresent>
<html:messages id="message" property="<%=ActionMessages.GLOBAL_MESSAGE%>">
<li><bean:write name="message"/></li>
</html:messages>
</logic:messagesPresent>

Errors are created and saved in ActionErrors
Messages are created and saved in ActionMessages

thanks!
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
What version of Struts are you using?

Here is what I do:

I use ActionMessages for errors and messages, I just store in different keys
errors are stored org.apache.struts.Globals.ERROR_KEY and messages are stored in org.apache.struts.Globals.MESSAGE_KEY

<html:messages id="msg" message="true">
<li class="message"><bean:write name="msg"/></li>
</html:messages>
<html:messages id="err" message="false">
<li class="error"><bean:write name="err"/></li>
</html:messages>
[ August 10, 2005: Message edited by: Kerry Wilson ]

http://www.goodercode.com
SCJP 1.4
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Thanks Kerry-
Turns out the problem is addressability to the MessageResources object:

Even though I was including my own MessageResources, in trace I see the code is using another one (I'm using Struts 1.2)...weird - haven't figured it out yet (but I see embedded property files in the struts.jar)- What I did was use one of the canned message types (message.simple)
and presto - I now get a message - might be a bug (but at least it works for now)..

thanks for the reply
Max
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
You should set your resource to not return null. So you will know when one is missing. You get a funky message like:

???RESOURCE_NAME???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionMessages causing me great distress
 
Similar Threads
Issues with <html:messages >
DISPLAYING MESSAGES USING html:messages TAG
Handling Messages (v1.2.9)
Using ActionMessages to display Errors using errors.headers and errors.footers
ActionMessages?????????