Hi,

As you may or may not know, I was looking in the exception management of struts and finally figured it out:

In your action when you add a message, you can add it in three ways:

               messages.add(Globals.ERROR_KEY, message);
               messages.add(Globals.MESSAGE_KEY, message);
               messages.add("any key", message);

Then you call: saveMessages(httpServletRequest, messages)

If your next forward is a jsp page, you will have access to those messages. To print them out, you use:

<html:messages id="whatever">

By default it will put the Globals.ERROR_KEY messages bean in whatever. If you want to use the Globals.MESSAGE_KEY, you need to use the:

<html:messages message="true" id="whatever">

And finally if you want to add some other messages (warnings for example) you can call the name of the property you selected:

<html:messages name="any key" id="whatever">

=======================
Exceptions:

When you throw an exception, struts automatically adds a message in the ERROR_KEY. This contains one additionnal variable that is the e.getMessage() of the exception. Therefore, if you declare an exception in your struts-config that forwards to an alert.jsp page and which points to a key: this.is.my.exception and that you define this key in your application.properties as follows :

this.is.my.exception=I got the following exception: {0}

Then if your alert.jsp page has a <html:messages id="whatever"> tag, it will display the message of your exception.

===========================
logic:messagesPresent

It is weird but the messagesPresent tag is also sensitive to the fact that it is an error or a message. Therefore it is not possible to do:

<logic:messagesPresent>
       <ul id="content-body-messages">
           <html:messages id="errorMsg">
               <li class="error"><bean:write name="errorMsg" /></li>
           </html:messages>
           <html:messages id="warn_key" name="warn_key">
               <li class="warning"><bean:write name="warn_key" /></li>
           </html:messages>
           <html:messages id="msg" message="true">
               <li class="success"><bean:write name="msg" /></li>
           </html:messages>
       </ul>
</logic:messagesPresent>

and have the messagesPresent test for either error or message. Instead you must do

       <ul id="content-body-messages">
<logic:messagesPresent>
           <html:messages id="errorMsg">
               <li class="error"><bean:write name="errorMsg" /></li>
           </html:messages>
           <html:messages id="warn_key" name="warn_key">
               <li class="warning"><bean:write name="warn_key" /></li>
           </html:messages>
</logic:messagesPresent>
<logic:messagesPresent message="true">
           <html:messages id="msg" message="true">
               <li class="success"><bean:write name="msg" /></li>
           </html:messages>
</logic:messagesPresent>
       </ul>

In order to test for both error and messages. This seems to be a new functionnality for struts 1.2.x (wherever we're at) because the first snippet used to work.

Anyways, this is just to help clarify the whole thing in case one of you gets the same kind of situation.

François



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Mdarad-toolbox-devs mailing list
Mdarad-toolbox-devs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mdarad-toolbox-devs

Reply via email to