org.apache.struts.action

Class DynaActionForm

public class DynaActionForm extends ActionForm implements DynaBean

Specialized subclass of ActionForm that allows the creation of form beans with dynamic sets of properties, without requiring the developer to create a Java class for each type of form bean.

USAGE NOTE - Since Struts 1.1, the reset method no longer initializes property values to those specified in <form-property> elements in the Struts module configuration file. If you wish to utilize that behavior, the simplest solution is to subclass DynaActionForm and call the initialize method inside it.

Since: Struts 1.1

Version: $Rev: 168012 $ $Date: 2005-05-03 23:39:10 +0100 (Tue, 03 May 2005) $

Field Summary
protected DynaActionFormClassdynaClass

The DynaActionFormClass with which we are associated.

protected HashMapdynaValues

The set of property values for this DynaActionForm, keyed by property name.

Method Summary
booleancontains(String name, String key)

Indicates if the specified mapped property contain a value for the specified key value.

Objectget(String name)

Return the value of a simple property with the specified name.

Objectget(String name, int index)

Return the value of an indexed property with the specified name.

Objectget(String name, String key)

Return the value of a mapped property with the specified name, or null if there is no value for the specified key.

DynaClassgetDynaClass()

Return the DynaClass instance that describes the set of properties available for this DynaBean.

protected DynaPropertygetDynaProperty(String name)

Return the property descriptor for the specified property name.

MapgetMap()

Returns the Map containing the property values.

StringgetString(String name)

Return the value of a String property with the specified name.

String[]getStrings(String name)

Return the value of a String[] property with the specified name.

voidinitialize(ActionMapping mapping)

Initialize all bean properties to their initial values, as specified in the {@link FormPropertyConfig} elements associated with the definition of this DynaActionForm.

voidinitialize(FormBeanConfig config)
protected booleanisDynaAssignable(Class dest, Class source)

Indicates if an object of the source class is assignable to the destination class.

voidremove(String name, String key)

Remove any existing value for the specified key on the specified mapped property.

voidreset(ActionMapping mapping, ServletRequest request)

Reset bean properties to their default state, as needed.

voidreset(ActionMapping mapping, HttpServletRequest request)

Reset bean properties to their default state, as needed.

voidset(String name, Object value)

Set the value of a simple property with the specified name.

voidset(String name, int index, Object value)

Set the value of an indexed property with the specified name.

voidset(String name, String key, Object value)

Set the value of a mapped property with the specified name.

voidsetDynaActionFormClass(DynaActionFormClass dynaClass)

Set the DynaActionFormClass instance with which we are associated.

StringtoString()

Render a String representation of this object.

Field Detail

dynaClass

protected DynaActionFormClass dynaClass

The DynaActionFormClass with which we are associated.

dynaValues

protected HashMap dynaValues

The set of property values for this DynaActionForm, keyed by property name.

Method Detail

contains

public boolean contains(String name, String key)

Indicates if the specified mapped property contain a value for the specified key value.

Parameters: name Name of the property to check key Name of the key to check

Throws: IllegalArgumentException if there is no property of the specified name

get

public Object get(String name)

Return the value of a simple property with the specified name.

Parameters: name Name of the property whose value is to be retrieved

Throws: IllegalArgumentException if there is no property of the specified name NullPointerException if the type specified for the property is invalid

get

public Object get(String name, int index)

Return the value of an indexed property with the specified name.

Parameters: name Name of the property whose value is to be retrieved index Index of the value to be retrieved

Throws: IllegalArgumentException if there is no property of the specified name IllegalArgumentException if the specified property exists, but is not indexed IndexOutOfBoundsException if the specified index is outside the range of the underlying property NullPointerException if no array or List has been initialized for this property

get

public Object get(String name, String key)

Return the value of a mapped property with the specified name, or null if there is no value for the specified key.

Parameters: name Name of the property whose value is to be retrieved key Key of the value to be retrieved

Throws: IllegalArgumentException if there is no property of the specified name IllegalArgumentException if the specified property exists, but is not mapped

getDynaClass

public DynaClass getDynaClass()

Return the DynaClass instance that describes the set of properties available for this DynaBean.

getDynaProperty

protected DynaProperty getDynaProperty(String name)

Return the property descriptor for the specified property name.

Parameters: name Name of the property for which to retrieve the descriptor

Throws: IllegalArgumentException if this is not a valid property name for our DynaClass

getMap

public Map getMap()

Returns the Map containing the property values. This is done mostly to facilitate accessing the DynaActionForm through JavaBeans accessors, in order to use the JavaServer Pages Standard Tag Library (JSTL).

For instance, the normal JSTL EL syntax for accessing an ActionForm would be something like this:

  ${formbean.prop}
The JSTL EL syntax for accessing a DynaActionForm looks something like this (because of the presence of this getMap() method):
  ${dynabean.map.prop}

getString

public String getString(String name)

Return the value of a String property with the specified name. This is equivalent to calling (String) dynaForm.get(name).

Parameters: name Name of the property whose value is to be retrieved

Throws: IllegalArgumentException if there is no property of the specified name NullPointerException if the type specified for the property is invalid ClassCastException if the property is not a String.

Since: Struts 1.2

getStrings

public String[] getStrings(String name)

Return the value of a String[] property with the specified name. This is equivalent to calling (String[]) dynaForm.get(name).

Parameters: name Name of the property whose value is to be retrieved

Throws: IllegalArgumentException if there is no property of the specified name NullPointerException if the type specified for the property is invalid ClassCastException if the property is not a String[].

Since: Struts 1.2

initialize

public void initialize(ActionMapping mapping)

Initialize all bean properties to their initial values, as specified in the {@link FormPropertyConfig} elements associated with the definition of this DynaActionForm.

Parameters: mapping The mapping used to select this instance

initialize

public void initialize(FormBeanConfig config)

isDynaAssignable

protected boolean isDynaAssignable(Class dest, Class source)

Indicates if an object of the source class is assignable to the destination class.

Parameters: dest Destination class source Source class

remove

public void remove(String name, String key)

Remove any existing value for the specified key on the specified mapped property.

Parameters: name Name of the property for which a value is to be removed key Key of the value to be removed

Throws: IllegalArgumentException if there is no property of the specified name

reset

public void reset(ActionMapping mapping, ServletRequest request)

Reset bean properties to their default state, as needed. This method is called before the properties are repopulated by the controller.

The default implementation attempts to forward to the HTTP version of this method.

Parameters: mapping The mapping used to select this instance request The servlet request we are processing

reset

public void reset(ActionMapping mapping, HttpServletRequest request)

Reset bean properties to their default state, as needed. This method is called before the properties are repopulated by the controller.

The default implementation (since Struts 1.1) does nothing. Subclasses may override this method to reset bean properties to default values, or the initialize method may be used to initialize property values to those provided in the form property configuration information (which was the behavior of this method in some release candidates).

Parameters: mapping The mapping used to select this instance request The servlet request we are processing

set

public void set(String name, Object value)

Set the value of a simple property with the specified name.

Parameters: name Name of the property whose value is to be set value Value to which this property is to be set

Throws: ConversionException if the specified value cannot be converted to the type required for this property IllegalArgumentException if there is no property of the specified name NullPointerException if the type specified for the property is invalid NullPointerException if an attempt is made to set a primitive property to null

set

public void set(String name, int index, Object value)

Set the value of an indexed property with the specified name.

Parameters: name Name of the property whose value is to be set index Index of the property to be set value Value to which this property is to be set

Throws: ConversionException if the specified value cannot be converted to the type required for this property IllegalArgumentException if there is no property of the specified name IllegalArgumentException if the specified property exists, but is not indexed IndexOutOfBoundsException if the specified index is outside the range of the underlying property

set

public void set(String name, String key, Object value)

Set the value of a mapped property with the specified name.

Parameters: name Name of the property whose value is to be set key Key of the property to be set value Value to which this property is to be set

Throws: ConversionException if the specified value cannot be converted to the type required for this property IllegalArgumentException if there is no property of the specified name IllegalArgumentException if the specified property exists, but is not mapped

setDynaActionFormClass

void setDynaActionFormClass(DynaActionFormClass dynaClass)

Set the DynaActionFormClass instance with which we are associated.

Parameters: dynaClass The DynaActionFormClass instance for this bean

toString

public String toString()

Render a String representation of this object.

Copyright © 2000-2008 - The Apache Software Foundation