Class ActionMessagesTool
- java.lang.Object
-
- org.apache.velocity.tools.struts.MessageResourcesTool
-
- org.apache.velocity.tools.struts.ActionMessagesTool
-
- Direct Known Subclasses:
ErrorsTool
@DefaultKey("messages") @ValidScope("request") public class ActionMessagesTool extends MessageResourcesTool
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 parameterproperty
that allows to select a specific category of messages to operate on. Without theproperty
parameter, methods operate on all action messages.
See the Struts User's Guide, section Building View Components for more information on this topic.
Template example(s): #if( $messages.exist() ) #foreach( $e in $messages.all ) $e <br> #end #end Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.struts.ActionMessagesTool"/> </toolbox> </tools>
This tool should only be used in the request scope.
- Since:
- VelocityTools 1.1
- Version:
- $Id: ActionMessagesTool.java 601976 2007-12-07 03:50:51Z nbubna $
- Author:
- Gabe Sidler, Nathan Bubna
-
-
Field Summary
Fields Modifier and Type Field Description protected ActionMessages
actionMsgs
A reference to the queued action messages.-
Fields inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
application, LOG, request
-
-
Constructor Summary
Constructors Constructor Description ActionMessagesTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
exist()
Returnstrue
if there are action messages queued, otherwisefalse
.boolean
exist(java.lang.String property)
Returns true if there are action messages queued for the specified category of messages, otherwisefalse
.java.util.List
get(java.lang.String property)
Returns the set of localized action messages as anjava.util.List
of strings for all actionMsgs queued of the specified category ornull
if no messages are queued for the specified category.java.util.List
get(java.lang.String property, java.lang.String bundle)
Returns the set of localized action messages as ajava.util.List
of strings for all action messages queued of the specified category ornull
if no action messages are queued for the specified category.protected ActionMessages
getActionMessages()
java.util.List
getAll()
Returns the set of localized action messages as anjava.util.List
of strings for all actionMsgs queued ornull
if no messages are queued.java.util.List
getAll(java.lang.String bundle)
Returns a List of all queued action messages using the specified message resource bundle.java.util.List
getGlobal()
This a convenience method and the equivalent of$messages.get($messages.globalName)
.java.lang.String
getGlobalName()
Returns the default "GLOBAL" category name that can be used for messages that are not associated with a particular property.int
getSize()
Returns the number of action messages queued.int
getSize(java.lang.String property)
Returns the number of action messages queued for a particular property.-
Methods inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
configure, getLocale, getResources, init
-
-
-
-
Method Detail
-
getActionMessages
protected ActionMessages getActionMessages()
-
exist
public boolean exist()
Returns
true
if there are action messages queued, otherwisefalse
.
-
exist
public boolean exist(java.lang.String property)
Returns true if there are action messages queued for the specified category of messages, otherwise
false
.- Parameters:
property
- the category of messages to check for
-
getSize
public int getSize()
Returns the number of action messages queued.
-
getSize
public int getSize(java.lang.String property)
Returns the number of action messages queued for a particular property.- Parameters:
property
- the category of messages to check for
-
getGlobal
public java.util.List getGlobal()
This a convenience method and the equivalent of
$messages.get($messages.globalName)
.Returns the set of localized action messages as an list of strings for all action messages queued of the global category or
null
if no messages are queued for the specified category. If the message resources don't contain an action message for a particular message key, the key itself is used.- Returns:
- a list of all messages stored under the "global" property
-
getAll
public java.util.List getAll()
Returns the set of localized action messages as anjava.util.List
of strings for all actionMsgs queued ornull
if no messages are queued. If the message resources don't contain a message for a particular key, the key itself is used as the message.
-
getAll
public java.util.List getAll(java.lang.String bundle)
Returns a List of all queued action messages using the specified message resource bundle.- Parameters:
bundle
- the message resource bundle to use- See Also:
getAll()
-
get
public java.util.List get(java.lang.String property)
Returns the set of localized action messages as anjava.util.List
of strings for all actionMsgs queued of the specified category ornull
if no messages are queued for the specified category. If the message resources don't contain a message for a particular key, the key itself is used as the message.- Parameters:
property
- the category of actionMsgs to operate on
-
get
public java.util.List get(java.lang.String property, java.lang.String bundle)
Returns the set of localized action messages as ajava.util.List
of strings for all action messages queued of the specified category ornull
if no action messages are queued for the specified category. If the message resources don't contain an action message for a particular action key, the key itself is used as action message.- Parameters:
property
- the category of actionMsgs to operate onbundle
- the message resource bundle to use
-
getGlobalName
public java.lang.String getGlobalName()
Returns the default "GLOBAL" category name that can be used for messages that are not associated with a particular property.
-
-