Class ActionMessages
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ActionErrors
A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.
Each individual message is described by an ActionMessage
object, which contains a message key (to be looked up in an appropriate
message resources database), and up to four placeholder arguments used for
parametric substitution in the resulting message.
IMPLEMENTATION NOTE - It is assumed that these objects are created and manipulated only within the context of a single thread. Therefore, no synchronization is required for access to internal collections.
- Since:
- Struts 1.1
- Version:
- $Rev$ $Date: 2005-08-26 21:58:39 -0400 (Fri, 26 Aug 2005) $
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
This class is used to store a set of messages associated with a property/key and the position it was initially added to list. -
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Have the messages been retrieved from this object?static final String
The "property name" marker to use for global messages, as opposed to those related to a specific property.protected int
The current number of the property/key being added.protected HashMap
<String, ActionMessages.ActionMessageItem> The accumulated set ofActionMessage
objects (represented as an ArrayList) for each property, keyed by property name. -
Constructor Summary
ConstructorDescriptionCreate an emptyActionMessages
object.ActionMessages
(ActionMessages messages) Create anActionMessages
object initialized with the given messages. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(String property, ActionMessage message) Add a message to the set of messages for the specified property.void
add
(ActionMessages actionMessages) Adds the messages from the givenActionMessages
object to this set of messages.void
clear()
Clear all messages recorded by this object.get()
Return the set of all recorded messages, without distinction by which property the messages are associated with.Return the set of messages related to a specific property.boolean
Returnstrue
if theget()
orget(String)
methods are called.boolean
isEmpty()
Returntrue
if there are no messages recorded in this collection, orfalse
otherwise.Return the set of property names for which at least one message has been recorded.int
size()
Return the number of messages recorded for all properties (including global messages).int
Return the number of messages associated with the specified property.toString()
Returns a String representation of this ActionMessages' property name=message list mapping.
-
Field Details
-
GLOBAL_MESSAGE
The "property name" marker to use for global messages, as opposed to those related to a specific property.
- See Also:
-
accessed
protected boolean accessedHave the messages been retrieved from this object?
The controller uses this property to determine if session-scoped messages can be removed.
- Since:
- Struts 1.2
-
messages
The accumulated set of
ActionMessage
objects (represented as an ArrayList) for each property, keyed by property name. -
iCount
protected int iCountThe current number of the property/key being added. This is used to maintain the order messages are added.
-
-
Constructor Details
-
ActionMessages
public ActionMessages()Create an empty
ActionMessages
object. -
ActionMessages
Create an
ActionMessages
object initialized with the given messages.- Parameters:
messages
- The messages to be initially added to this object. This parameter can benull
.- Since:
- Struts 1.1
-
-
Method Details
-
add
Add a message to the set of messages for the specified property. An order of the property/key is maintained based on the initial addition of the property/key.
- Parameters:
property
- Property name (or ActionMessages.GLOBAL_MESSAGE)message
- The message to be added
-
add
Adds the messages from the given
ActionMessages
object to this set of messages. The messages are added in the order they are returned from theproperties
method. If a message's property is already in the currentActionMessages
object, it is added to the end of the list for that property. If a message's property is not in the current list it is added to the end of the properties.- Parameters:
actionMessages
- TheActionMessages
object to be added. This parameter can benull
.- Since:
- Struts 1.1
-
clear
public void clear()Clear all messages recorded by this object.
-
isEmpty
public boolean isEmpty()Return
true
if there are no messages recorded in this collection, orfalse
otherwise.- Returns:
true
if there are no messages recorded in this collection;false
otherwise.- Since:
- Struts 1.1
-
get
Return the set of all recorded messages, without distinction by which property the messages are associated with. If there are no messages recorded, an empty enumeration is returned.
- Returns:
- An iterator over the messages for all properties.
-
get
Return the set of messages related to a specific property. If there are no such messages, an empty enumeration is returned.
- Parameters:
property
- Property name (or ActionMessages.GLOBAL_MESSAGE)- Returns:
- An iterator over the messages for the specified property.
-
isAccessed
public boolean isAccessed()Returns
true
if theget()
orget(String)
methods are called.- Returns:
true
if the messages have been accessed one or more times.- Since:
- Struts 1.2
-
properties
Return the set of property names for which at least one message has been recorded. If there are no messages, an empty
Iterator
is returned. If you have recorded global messages, theString
value ofActionMessages.GLOBAL_MESSAGE
will be one of the returned property names.- Returns:
- An iterator over the property names for which messages exist.
-
size
public int size()Return the number of messages recorded for all properties (including global messages). NOTE - it is more efficient to call
isEmpty
if all you care about is whether or not there are any messages at all.- Returns:
- The number of messages associated with all properties.
-
size
Return the number of messages associated with the specified property.
- Parameters:
property
- Property name (or ActionMessages.GLOBAL_MESSAGE)- Returns:
- The number of messages associated with the property.
-
toString
Returns a String representation of this ActionMessages' property name=message list mapping.
-