The Velocity Project < Velocity Tools - Struts >

Velocity Tools

VelocityStruts

VelocityStruts Tools

Other Subprojects

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.

Class
 org.apache.velocity.tools.struts.ActionMessagesTool
Name
 $messages (this is the recommended name of the tool in the Velocity context)
Toolbox Configuration Example
 
<tool>
  <key>messages</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.struts.ActionMessagesTool</class>
</tool>
Author(s)
  Gabriel Sidler
Nathan Bubna
Method Overview
exist() Returns true if there are action messages queued, otherwise false.
getSize() Returns the number of action messages queued.
getGlobal() This a convenience method and the equivalent of $messages.get($messages.globalName)
getAll() Returns a list of localized action messages for all action messages queued.
get() Returns a list of localized action messages for a particular category of action messages.

exist()

Returns true if there are action messages queued, otherwise false.

boolean exist()

boolean exist(String property)

Parameters
property
The category of messages to check for.
Returns
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)

Parameters
property
The category of action messages to operate on.
Returns
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()

Returns
A list of all messages stored under the "global" property.

See 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)

Parameters
bundle
The (non-default) message-resources bundle that holds the action messages.
Returns
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
#end

This 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)

Parameters
property
The category of action messages to return.
bundle
The (non-default) message-resources bundle that holds the action messages.
Returns
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
#end

This 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>



Copyright © 1999-2003, Apache Software Foundation