Antonio Petrelli wrote:
2008/6/16 Dimitris Mouchritsas <[EMAIL PROTECTED]>:
Hi all,
we're using struts 1.2.4 in our project and we have 3 types of messages to
show the user:

1) Confirmational, with say a green tick mark,
2) Informational, with a classic i in a bubble
3) Error messages, with the classes red rectangle.

Currently I use saveErrors and saveMessages in my actions but that gives me
only 2 kinds of messages;
errors and all others. Is there a way to add a 3rd type? I think I should do
it by

errors.add("My.Custom.Identifier", ....);

but I'm not sure.

Well, this is the right thing to do :-)
In fact, saveErrors and saveMessages put the messages using special keys:
Globals.ERROR_KEY:
http://struts.apache.org/1.2.4/api/org/apache/struts/Globals.html#ERROR_KEY
Globals.MESSAGE_KEY:
http://struts.apache.org/1.2.4/api/org/apache/struts/Globals.html#MESSAGE_KEY

HTH
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Ok, I've succeeded, but in trying to have a uniform method for all messages I lost struts validator's errors.
For example, in the action:

       ActionMessages msg = new ActionMessages();

msg.add(MyConstants.MESSAGE_CONFIRM, new ActionMessage("prompt.OK")); msg.add(MyConstants.MESSAGE_INFO, new ActionMessage("prompt.modify")); msg.add(MyConstants.MESSAGE_ERROR, new ActionMessage("prompt.close"));

       saveMessages(request, msg);

then in the jsp, we have a tile to show all messages, regardless of where they come from:

<logic:messagesPresent message="true" property="<%=MyConstants.MESSAGE_CONFIRM%>">
   <div id="Message" class="Success">
       <%--<p><strong>Your changes have been accepted</strong>.</p>--%>
<html:messages id="msg" message="true" property="<%=MyConstants.MESSAGE_CONFIRM%>">
           <p>
               <bean:write name="msg" />
</p> </html:messages>
       <p class="Buttons">
<button id="MClose" type="submit"><bean:message key="prompt.close" /></button>
       </p>
   </div><!-- Message // -->
</logic:messagesPresent>


<%-- Informational Messages --%>
<logic:messagesPresent message="true" property="<%=MyConstants.MESSAGE_INFO%>">
   <div id="Message" class="Info">

<html:messages id="msg" message="true" property="<%=MyConstants.MESSAGE_INFO%>"> <p><bean:write name="msg" /></p> </html:messages> <p class="Buttons"> <button id="MClose" type="submit"><bean:message key="prompt.close" /></button>
       </p>
   </div><!-- Message // -->
</logic:messagesPresent>

<%-- Error messages --%>
<logic:messagesPresent message="true" property="<%=MyConstants.MESSAGE_ERROR%>">
   <div id="Message" class="Error">
       <p><strong><bean:message key="error.occured" />:</strong></p>
       <ul>
<html:messages id="msg" message="true" property="<%=MyConstants.MESSAGE_ERROR%>">
               <li>
                   <bean:write name="msg" />
               </li>
           </html:messages>
           <%--
           <li><a href="#FName">First name</a> is required.</li>
           <li><a href="#LName">Last name</a> is required.</li>
           --%>
</ul> <p class="Buttons"> <button id="MClose" type="submit"><bean:message key="prompt.close" /></button>
       </p>
   </div><!-- Message // -->
</logic:messagesPresent>

But by using this method, the errors that validator adds, are not displayed, because they're save under Globals.ERROR_KEY. Is there a way to tell validator to save its errors as a message under my own custom key? Again I point out that the only reason I want this is to have a uniform way of dealing with messages, not having to use saveErrors. But if this is not correct I guess I'll
revert into using saveErrors. Any suggestions?

Regards
Dimitris



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to