You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Zmitko, Jan" <Ja...@Dresdner-Bank.com> on 2006/10/27 19:00:04 UTC

ActionMessage and severity level

Hi,

I´ll implement handling of messages which allowes me to differ beetween miscellaneous kinds of message types. An example for an application is, that these different kind of messages should have different varying format in the GUI.

Because the struts framework doesn´t provide this feature, such as the java server faces framework, I think to extend the "org.apache.struts.action.ActionMessage" by these properties and implement corresponding mechanism to the own basis action implementation. 

Have someone similar request solved and can give me tips. Maybe there exists solution also in the struts framework which I´ve ignore?

Thanks for any Feedback.

Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ActionMessage and severity level

Posted by Niall Pemberton <ni...@gmail.com>.
On 10/27/06, Zmitko, Jan <Ja...@dresdner-bank.com> wrote:
> Hi,
>
> I´ll implement handling of messages which allowes me to differ beetween miscellaneous kinds of message types. An example for an application is, that these different kind of messages should have different varying format in the GUI.
>
> Because the struts framework doesn´t provide this feature, such as the java server faces framework, I think to extend the "org.apache.struts.action.ActionMessage" by these properties and implement corresponding mechanism to the own basis action implementation.
>
> Have someone similar request solved and can give me tips. Maybe there exists solution also in the struts framework which I´ve ignore?

Theres a couple of possibilities which may work for you.

1) Store the ActionMessages under different keys, based on "severity".

Store provides an easy mechanism to store and display messages under
two different keys:

1.1) Errors - Globals.ERROR_KEY
The saveErrors() method in Action stores the ActionMessages under the
Globals.ERROR_KEY key and using <html:messages message="false"> will
display them

1.2) Messages - Globals.MESSAGE_KEY
The saveMessages() method in Action stores the ActionMessages under
the Globals.MESSAGE_KEY key and using <html:messages message="false">
will display them

If you wanted three levels of "severity" (e.g. message, warning and
error) you could for example use the above for two levels and store
your "warning" messages under a different custom key (e.g.
"WARNINGS").

If you store the "warning" messages in a separate ActionMessages
object and save them in the request under that key....

   ActionMessages myWarnings = new ActionMessages();
   myWarnings.add("foo", new ActionMessage("...");
   request.setAttribute("WARNINGS", myWarnings);

...then you can display them using the <html:messages> tag in the following way:

   <html:messages name="WARNINGS" id="...">

2) Use the "property" attribute
If you don't have a need to associate messages with a property - then
you could re-use that for your severity:

   ActionMessages errors = new ActionMessages();
   errors.add("info", new ActionMessage("foo.key"));
   errors.add("warning", new ActionMessage("bar.key"));
   ... etc

Obviously you loose the ability to filter messages by property
(usually used to place messages next to the field they relate to)
doing this, but you can then display the different types separately,
using the propery attribute:

   <html:messages property="info" id="...">

If neither of the above approaches suit your needs (maybe you want to
dislay the different message types together, but just with a different
style) - then I guess you're left with the route you're proposting
(having your own ActionMessage implementation) - but you'll need to
write the equivalent of <html:messages> (or <html:errors>) in order to
display them.

More info and examples here:
http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html

Niall


> Thanks for any Feedback.
>
> Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org