ActionMessages (Apache Struts API Documentation)
Keywords: org.apache.struts.action.ActionMessages,ActionMessages class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts.action
Class ActionMessages

    java.lang.Object
      |
      +--org.apache.struts.action.ActionMessages

All Implemented Interfaces:
  java.io.Serializable

Direct Known Subclasses:
  ActionErrors

public class ActionMessages
extends java.lang.Object
implements java.io.Serializable

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:
  $Revision: 1.1 $ $Date: 2003-08-22 09:14:33 +0100 (Fri, 22 Aug 2003) $
Author:
  David Geary, Craig R. McClanahan, David Winterfeldt, David Graham
See Also:
  Serialized Form

Nested Class Summary
`protected class` | `ActionMessages.ActionMessageItem` 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
`static java.lang.String` | `GLOBAL_MESSAGE` The "property name" marker to use for global messages, as opposed to those related to a specific property.
`protected int` | `iCount` The current number of the property/key being added.
`protected java.util.HashMap` | `messages` The accumulated set of `ActionMessage` objects (represented as an ArrayList) for each property, keyed by property name.

Constructor Summary
`ActionMessages()` Create an empty `ActionMessages` object.
`ActionMessages(ActionMessages messages)` Create an `ActionMessages` object initialized with the given messages.

Method Summary
`void` | `add(ActionMessages messages)` Adds the messages from the given `ActionMessages` object to this set of messages.
`void` | `add(java.lang.String property, ActionMessage message)` Add a message to the set of messages for the specified property.
`void` | `clear()` Clear all messages recorded by this object.
`boolean` | `empty()` Deprecated. Use isEmpty instead.
`java.util.Iterator` | `get()` Return the set of all recorded messages, without distinction by which property the messages are associated with.
`java.util.Iterator` | `get(java.lang.String property)` Return the set of messages related to a specific property.
`boolean` | `isEmpty()` Return `true` if there are no messages recorded in this collection, or `false` otherwise.
`java.util.Iterator` | `properties()` 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` | `size(java.lang.String property)` Return the number of messages associated with the specified property.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### GLOBAL_MESSAGE

    public static final java.lang.String GLOBAL_MESSAGE

  The "property name" marker to use for global messages, as opposed to those related to a specific property.

  See Also:
    Constant Field Values

### messages

    protected java.util.HashMap messages

  The accumulated set of `ActionMessage` objects (represented as an ArrayList) for each property, keyed by property name.

### iCount

    protected int iCount

  The current number of the property/key being added. This is used to maintain the order messages are added.

Constructor Detail

### ActionMessages

    public ActionMessages()

  Create an empty `ActionMessages` object.

### ActionMessages

    public ActionMessages(ActionMessages messages)

  Create an `ActionMessages` object initialized with the given messages.

Parameters:
  `messages` - The messages to be initially added to this object. This parameter can be `null`.
Since:
  Struts 1.1

Method Detail

### add

    public void add(java.lang.String property,
                    ActionMessage message)

  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

    public void add(ActionMessages messages)

  Adds the messages from the given `ActionMessages` object to this set of messages. The messages are added in the order they are returned from the properties() method. If a message's property is already in the current `ActionMessages` 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:
    `messages` - The `ActionMessages` object to be added. This parameter can be `null`.
  Since:
    Struts 1.1

### clear

    public void clear()

  Clear all messages recorded by this object.

### empty

    public boolean empty()

  Deprecated. Use isEmpty instead.

  Return `true` if there are no messages recorded in this collection, or `false` otherwise.

### isEmpty

    public boolean isEmpty()

  Return `true` if there are no messages recorded in this collection, or `false` otherwise.

  Since:
    Struts 1.1

### get

    public java.util.Iterator 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.

### get

    public java.util.Iterator get(java.lang.String property)

  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)

### properties

    public java.util.Iterator 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, the String value of `ActionMessages.GLOBAL_MESSAGE` will be one of the returned property names.

### size

    public int size()

  Return the number of messages recorded for all properties (including global messages). NOTE - it is more efficient to call `empty()` if all you care about is whether or not there are any messages at all.

### size

    public int size(java.lang.String property)

  Return the number of messages associated with the specified property.

  Parameters:
    `property` - Property name (or ActionMessages.GLOBAL_MESSAGE)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2003 - Apache Software Foundation