ActionMessagesTool Reference Documentation
This tool deals with Struts action messages. A few important aspects about action
messages are:
- Action message strings are looked up in the message resources. Support
for internationalized messages is provided.
- Action messages can have up to five replacement parameters.
- Actions have an attribute
property
that describes the category of
message. This allows the view designer to place action messages precisely where they are
wanted. Several methods of this tool provide a parameter
property
that allows to select a specific category of messages to operate
on. Without the property
parameter, methods operate on all action messages.
See the Struts User's Guide, section
Building View Components
for more information on this topic.
@@@version@@@, @@@date@@@org.apache.velocity.tools.struts.ActionMessagesTool$messagesGabriel SidlerNathan Bubna<tool>
<key>messages</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ActionMessagesTool</class>
</tool>The Javadoc for more info.
exist()
Returns true
if there are action messages queued,
otherwise false
.
boolean exist()
boolean exist(String property)
The category of messages to check for.
true
if there are action messages queued. false
otherwise.
Calling exist()
without the property
parameter checks for action messages of
any category. The property
parameter can be used to limit the check to
action messages of a specific category.
$errors.exist()
$errors.exist("password")
getSize()
Returns the number of action messages queued.
int getSize()
int getSize(String property)
The category of action messages to operate on.
The number of action messages.
Calling getSize()
without the property
parameter returns the total
number of queued action messages. The property
parameter can be used to
obtain the number of queued action messages for a specific category.
$messages.getSize()
$messages.size
$messages.getSize("password")
getGlobal()
This a convenience method and the equivalent of
$messages.get($messages.globalName)
List getGlobal()
A list of all messages stored under the "global" property.
The the section on get() for more information.
getAll()
Returns a list of localized action messages for all action messages queued.
List getAll()
List getAll(String bundle)
The (non-default) message-resources bundle that holds the action messages.
If the message resources are lacking an action message message for a
particular message key, the key itself is used as an action message
and a warning is logged.
The following example shows a macro to render the action messages:
#macro (messagesMarkup)
#if ($messages.exist())
<ul>
#foreach ($e in $messages.all )
<li>$e</li>
#end
</ul>
#end
#endThis produces output similar to the following:
<ul>
<li>This is the first action message in the queue.</li>
<li>This is the second action message in the queue.</li>
</ul>
get()
Returns a list of localized action messages for a particular category
of action messages.
List get(String property)
List get(String property, String bundle)
The category of action messages to return.
The (non-default) message-resources bundle that holds the action messages.
A java.util.List
of java.lang.String
.
If no action messages exist for the specified category,
null
is returned.
If the message resources are lacking an error message for a
particular message key, the key itself is used as an action message
and a warning is logged.
The following example shows a macro to render the action messages for a
particular category of action messages:
#macro (messagesMarkup $property)
#if ($messages.exist($property))
<ul>
#foreach ($er in $messages.get($property) )
<li>$er</li>
#end
</ul>
#end
#endThis produces output similar to the following:
<ul>
<li>This is the first action message in the queue.</li>
<li>TThis is the second action message in the queue.</li>
</ul>