oracle.jheadstart.view.struts
Class JhsDynaActionForm

java.lang.Object
  extended byorg.apache.struts.action.ActionForm
      extended byorg.apache.struts.action.DynaActionForm
          extended byorg.apache.struts.validator.DynaValidatorForm
              extended byoracle.jheadstart.view.struts.JhsDynaActionForm
All Implemented Interfaces:
java.lang.Cloneable, org.apache.commons.beanutils.DynaBean, java.util.Iterator, java.io.Serializable
Direct Known Subclasses:
DynaBeanReadOnly

public class JhsDynaActionForm
extends org.apache.struts.validator.DynaValidatorForm
implements java.util.Iterator, java.lang.Cloneable

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.

See Also:
Serialized Form

Field Summary
protected static java.util.ArrayList actionAttributes
           
protected  java.lang.Integer iteratorRowIndex
          This is only non-null if the instance is a clone of a JhsDynaFormBean created in the next() or in the get(String) method.
protected  DataObject mDataObject
           
protected  DataObjectSet mDataObjectSet
           
protected  boolean mInitialized
           
protected  int mMaxIndex
           
protected  java.util.Map mPropertyConfigs
           
protected  SessionData mSessionData
           
protected  boolean mValidationMode
           
protected  java.lang.Integer tempRowIndex
          This is set to a non-null value if we encounter a "isIndexIterator" PropertyConfig.
 
Fields inherited from class org.apache.struts.validator.DynaValidatorForm
page, validatorResults
 
Fields inherited from class org.apache.struts.action.DynaActionForm
dynaClass, dynaValues
 
Fields inherited from class org.apache.struts.action.ActionForm
multipartRequestHandler, servlet
 
Constructor Summary
JhsDynaActionForm()
           
 
Method Summary
protected  java.util.ArrayList createEmptyArrayList(org.apache.struts.config.FormPropertyConfig config, int length)
           
protected  java.lang.String[] createStringArray(DataObjectSet dataObjectSet, java.lang.String attribute)
           
protected  java.lang.String[] createStringArray(java.lang.String dataObjectSetName, java.lang.String attribute)
           
 java.lang.Object get(java.lang.String name)
           
 java.lang.Object get(java.lang.String name, boolean beanValueOnly)
           
 java.lang.Object get(java.lang.String name, int index)
           
 java.lang.Object get(java.lang.String name, int index, boolean beanValueOnly)
           
 java.lang.Object getArray(java.lang.String name)
          Returns an Array of property values for properties on form beans that wrap a DataObjectSet.
protected  java.lang.Object getAttributeForDisplay(DataObject bean, java.lang.String name, JhsFormPropertyConfig config)
           
protected  java.lang.Object getAttributeForDisplay(java.lang.String name, JhsFormPropertyConfig config)
           
 java.lang.Object getConvertedBeanValue(java.lang.String name)
          This method retrieves the value as populated on the Bean and converts it to the appropriate type: When the custom property isDateField or isDateTimeField is set to true on the form bean definition in Struts-config, the value is converted to a Date.
 java.util.Map getMap()
          Override of the default getMap() that always returns dynaValues.
 int getMaxIndex()
          Initializes mMaxIndex if necessary, and returns it.
 java.lang.Object getMetaProperty(java.lang.String name)
          Checks whether the attribute is a 'reserved attribute' that will return some meta information about the formbean itself.
 SessionData getSessionData()
           
 boolean hasNext()
          returns true if we are not yet at the last row
 void initProperties()
           
 void initPropertyArrays(boolean checkResetFlag)
           
protected  void initPropertyConfigs(org.apache.struts.action.ActionMapping mapping)
           
 java.lang.Object next()
          Get the next DataObject from the DataObjectSet encapsulated by this bean and wrap it as a new instance of JhsDynaActionForm.
 void remove()
          bean is readOnly, throws UnsupportedOperationException.
 void reset(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
           
 void resetMaxIndex()
          ADVANCED METHOD! ONLY NEEDED IN SPECIAL CIRCUMSTANCES, NORMALLY MAXINDEX IS KEPT UPTODATE BY OTHER METHODS IN THIS CLASS
 void set(java.lang.String name, int index, java.lang.Object value)
           
 void set(java.lang.String name, java.lang.Object value)
           
 void setDataObject(DataObject dataObject)
           
 void setDataObjectSet(DataObjectSet set)
           
 void setIteratorRowIndex(int index)
          This method gets called from the next() method in this class.
 void setSessionData(SessionData sessionData)
           
 void setValidationMode(boolean mode)
           
 java.lang.String toString()
           
 org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
          When the Struts validation framework validates this bean, we need to return the request values and not the DataObject values.
 
Methods inherited from class org.apache.struts.validator.DynaValidatorForm
getPage, getResultValueMap, getValidatorResults, log, log, setPage, setValidatorResults
 
Methods inherited from class org.apache.struts.action.DynaActionForm
contains, get, getDynaClass, getDynaProperty, initialize, isDynaAssignable, remove, reset, set
 
Methods inherited from class org.apache.struts.action.ActionForm
getMultipartRequestHandler, getServlet, getServletWrapper, setMultipartRequestHandler, setServlet, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.beanutils.DynaBean
contains, get, getDynaClass, remove, set
 

Field Detail

mMaxIndex

protected int mMaxIndex

mDataObjectSet

protected DataObjectSet mDataObjectSet

mDataObject

protected DataObject mDataObject

mInitialized

protected boolean mInitialized

mValidationMode

protected boolean mValidationMode

mPropertyConfigs

protected java.util.Map mPropertyConfigs

mSessionData

protected SessionData mSessionData

actionAttributes

protected static java.util.ArrayList actionAttributes

tempRowIndex

protected java.lang.Integer tempRowIndex
This is set to a non-null value if we encounter a "isIndexIterator" PropertyConfig. See JhsFormPropertyConfig for more information.


iteratorRowIndex

protected java.lang.Integer iteratorRowIndex
This is only non-null if the instance is a clone of a JhsDynaFormBean created in the next() or in the get(String) method.

Constructor Detail

JhsDynaActionForm

public JhsDynaActionForm()
Method Detail

setIteratorRowIndex

public void setIteratorRowIndex(int index)
This method gets called from the next() method in this class. It is therefore only used in the (short-lived) clones of the JhsDynaActionForm inside a tag. For more information, see the next() method.


getSessionData

public SessionData getSessionData()

setSessionData

public void setSessionData(SessionData sessionData)

setDataObjectSet

public void setDataObjectSet(DataObjectSet set)

initPropertyArrays

public void initPropertyArrays(boolean checkResetFlag)

initProperties

public void initProperties()

createEmptyArrayList

protected java.util.ArrayList createEmptyArrayList(org.apache.struts.config.FormPropertyConfig config,
                                                   int length)

setDataObject

public void setDataObject(DataObject dataObject)

reset

public void reset(org.apache.struts.action.ActionMapping mapping,
                  javax.servlet.http.HttpServletRequest request)

initPropertyConfigs

protected void initPropertyConfigs(org.apache.struts.action.ActionMapping mapping)

resetMaxIndex

public void resetMaxIndex()
ADVANCED METHOD! ONLY NEEDED IN SPECIAL CIRCUMSTANCES, NORMALLY MAXINDEX IS KEPT UPTODATE BY OTHER METHODS IN THIS CLASS


getMaxIndex

public int getMaxIndex()
Initializes mMaxIndex if necessary, and returns it.


getConvertedBeanValue

public java.lang.Object getConvertedBeanValue(java.lang.String name)
                                       throws java.lang.Exception
This method retrieves the value as populated on the Bean and converts it to the appropriate type: When the custom property isDateField or isDateTimeField is set to true on the form bean definition in Struts-config, the value is converted to a Date.

Throws:
java.lang.Exception

getMetaProperty

public java.lang.Object getMetaProperty(java.lang.String name)
Checks whether the attribute is a 'reserved attribute' that will return some meta information about the formbean itself. Because the bean implements DynaBean, it is not possible to use any getter such as getMaxIndex on the bean; the get(String) method will be called instead. Properties supplied at this time are: - rowCount: the number of rows in the bean - maxIndex: rowCount - 1 - persistentRowCount: number of rows in the actual DataObjectSet, not in the dynavalues. Should you have a "real" attribute on the DataObject with, for instance, the name "rowCount", you can prevent this method from returning the meta value by setting the persistentAttribute property in the property config also to "rowCount".

Parameters:
name -
Returns:
The meta information requested for one of the reserved attributes, null otherwise.

get

public java.lang.Object get(java.lang.String name)
Specified by:
get in interface org.apache.commons.beanutils.DynaBean

get

public java.lang.Object get(java.lang.String name,
                            boolean beanValueOnly)

get

public java.lang.Object get(java.lang.String name,
                            int index)
Specified by:
get in interface org.apache.commons.beanutils.DynaBean

get

public java.lang.Object get(java.lang.String name,
                            int index,
                            boolean beanValueOnly)

set

public void set(java.lang.String name,
                int index,
                java.lang.Object value)
Specified by:
set in interface org.apache.commons.beanutils.DynaBean

createStringArray

protected java.lang.String[] createStringArray(java.lang.String dataObjectSetName,
                                               java.lang.String attribute)

createStringArray

protected java.lang.String[] createStringArray(DataObjectSet dataObjectSet,
                                               java.lang.String attribute)

toString

public java.lang.String toString()

validate

public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping,
                                                      javax.servlet.http.HttpServletRequest request)
When the Struts validation framework validates this bean, we need to return the request values and not the DataObject values. Therefore, before calling the super.validate() method, we set the ValidationMode to true (so that the get() method returns request values), an immediately after that we reset ValidationMode to false.


setValidationMode

public void setValidationMode(boolean mode)

getAttributeForDisplay

protected java.lang.Object getAttributeForDisplay(java.lang.String name,
                                                  JhsFormPropertyConfig config)

getAttributeForDisplay

protected java.lang.Object getAttributeForDisplay(DataObject bean,
                                                  java.lang.String name,
                                                  JhsFormPropertyConfig config)

hasNext

public boolean hasNext()
returns true if we are not yet at the last row

Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Get the next DataObject from the DataObjectSet encapsulated by this bean and wrap it as a new instance of JhsDynaActionForm. To create this instance, we clone the original JhsDynaActionForm. Then we clear the DataObjectSet, and set the DataObject of this clone with the current DataObject. This takes care of all the properties that are derived from the DataObject. Only for "transient" PropertyConfigs we have a problem; they were initialized with empty ArrayLists in the dynaValues map, but the clone is meant to have single-row behaviour and should return null and not an array of nulls. Therefore, we call the setIteratorRowIndex method on the clone, and on the "get(name)" methods we check for the presence of the iteratorRowIndex attribute and if it exists, it must mean we are using a clone, and therefore need to return the value with index iteratorRowIndex from the ArrayList.

Specified by:
next in interface java.util.Iterator

remove

public void remove()
bean is readOnly, throws UnsupportedOperationException.

Specified by:
remove in interface java.util.Iterator

set

public void set(java.lang.String name,
                java.lang.Object value)
Specified by:
set in interface org.apache.commons.beanutils.DynaBean

getArray

public java.lang.Object getArray(java.lang.String name)
Returns an Array of property values for properties on form beans that wrap a DataObjectSet. Needed for JSTL support, to explicitly return an array for a Form Bean property in case the Form Bean has wrapped a DataObjectSet. Note that the default implementation of get() may also return an array, but its behavior seems somewhat unclear.


getMap

public java.util.Map getMap()
Override of the default getMap() that always returns dynaValues. This method returns a Map that gives access to all keys and values for all properties in the Form Bean. This method is primarily used to access Struts Form Beans from JSTL EL Expressions, not used by JHeadstart. Note that the values returned from this Map are in fact retrieved from the get() method on the DynaActionFormBean.