I like the second approach better as it means I only have to keep
track of one message collection in each individual action. It just
means that I don't use the GLOBAL_MESSAGE constant, but I think I can
live with that.

Thanks Niall :)

Chris

On 6/7/06, Niall Pemberton <[EMAIL PROTECTED]> wrote:
You can do this in different ways:

1) Store the two different sets of messages in different
ActionMessages objects under different keys in the request or session.

So for example in your action you could store the search messages
using a session attribute key of "search-messages" - in your Action
you might have:

  ActionMessages searchMsgs = new ActionMessages();
  searchMsgs.add("fooSearch", new ActionMessage("foo.search.key"));
  searchMsgs.add("barSearch", new ActionMessage("bar.search.key"));
  session.setAttribute("search-messages", searchMsgs);

Then to display these messages, you use the "name" attribute

  <logic:messagesPresent name="search-messages">
      <html:messages name="search-messages" id="...">
          ....
      </html:messages>
  </logic:messagesPresent>

You could then store your "global" messages under the default Struts
"messages" key - so in your Action you might have

  ActionMessages globalMsgs = new ActionMessages();
  globalMsgs.add("fooGlobal", new ActionMessage("foo.global.key"));
  globalMsgs.add("barGlobal", new ActionMessage("bar.global.key"));
  saveMessages(session, globalMsgs);

Then to display these messages, you use the message="true" attribute

  <logic:messagesPresent message="true">
      <html:messages message="true" id="...">
          ....
      </html:messages>
  </logic:messagesPresent>

This saveMesages() method and message="true" attribute are just a
convenience feature so that you don't have to specify a key in the
request/session to save them under and to display them.

2) The second option is to save both sets of messages in one
ActionMessages object and use the "property" attribute to filter the
two different types. So add search messages with a property of
"search" and global messages with a property of "global":

  ActionMessages msgs = new ActionMessages();
  msgs.add("search", new ActionMessage("foo.search.key"));
  msgs.add("search", new ActionMessage("bar.search.key"));
  msgs.add("global", new ActionMessage("foo.global.key"));
  msgs.add("global", new ActionMessage("bar.global.key"));
  saveMessages(session, msgs);

To Show the global messages:

  <logic:messagesPresent message="true" property="global">
      <html:messages message="true" property="global" id="...">
          ....
      </html:messages>
  </logic:messagesPresent>

To Show the search messages:

  <logic:messagesPresent message="true" property="search">
      <html:messages message="true" property="search" id="...">
          ....
      </html:messages>
  </logic:messagesPresent>

The limitation on this approach is that you need to use the same
property name for the messages of a specified type.

I put up some notes on messages a while back here:
http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html

Niall

> Thanks,
>
> Chris

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



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

Reply via email to