Simple,
Separate your messages
and your warnings
: In your struts action, save your messages and warnings as follows:
//For messages
saveMessages(request, messages);
//For warnings
saveErrors(request, warnings);
To display them:
<logic:messagesPresent message="true">
<html:messages id="aMsg" message="true">
<logic:present name="aMsg">
<!-- Messages -->
<div class="messages">
<bean:write name="aMsg" filter="false" />
</div>
</logic:present>
</html:messages>
</logic:messagesPresent>
<logic:messagesPresent message="false">
<html:messages id="aMsg" message="false">
<logic:present name="aMsg">
<!-- Warnings-->
<div class="warnings">
<bean:write name="aMsg" filter="false" />
</div>
</logic:present>
</html:messages>
</logic:messagesPresent>
This displays all messages
(by setting message="true"
)
<html:messages id="aMsg" message="true">
This displays all warnings
(by setting message="false"
)
<html:messages id="aMsg" message="true">
UPDATE Seeing that you're now clearing your question, the simplest way would be to do this.
Have a certain flag that will indicate whether the user would like to view messages
or warnings
. On the Struts Action, request the flag and check if the user selected viewing messages or warnings.
You then save either warnings
or messages
based on the user selection and display the same page (as you wrote above) to display messages.
The reason is this, Struts (when storing you messages or errors) stores it on request or session with the following constant.
- Globals.MESSAGE_KEY (that is assigned when you do
saveMessages(request, messages)
)
- Globals.ERROR_KEY (that is assigned when you do
saveErrors(request, errors)
)
when using <logic:messagesPresent message="true">
, Struts searches for the MESSAGE_KEY
(if message=true) or ERROR_KEY
(if message=false) or both (if message=none). You have no control of that.
<html:messages />
TLD comments states:
By default the tag will retrieve the
bean it will iterate over from the
Globals.ERROR_KEY constant string,
but if this attribute is set to 'true'
the bean will be retrieved from the
Globals.MESSAGE_KEY constant string.
Also if this is set to 'true', any
value assigned to the name attribute
will be ignored.
You can also write scriptlet to check if those keys exists, then <logic:iterate />
through the key to display the messages (but that'll be too much work).
Hope this helps.