org.apache.struts.validator
Class LazyValidatorForm

java.lang.Object
  |
  +--org.apache.struts.action.ActionForm
        |
        +--org.apache.struts.validator.ValidatorForm
              |
              +--org.apache.struts.validator.BeanValidatorForm
                    |
                    +--org.apache.struts.validator.LazyValidatorForm
All Implemented Interfaces:
org.apache.commons.beanutils.DynaBean, java.io.Serializable

public class LazyValidatorForm
extends BeanValidatorForm

Struts Lazy ActionForm which wraps a LazyDynaBean.

There isn't really that much to this implementation as most of the lazy behaviour is in LazyDynaBean and wrapping the LazyDynaBean is handled in the parent BeanValidatorForm. The only thing it really does is populate indexed properties which are a List type with a LazyDynaBean in the get(name, index) method.

Lazy DynaBeans provide several types of lazy behaviour:

Using this lazy ActionForm means that you don't have to define the ActionForm's properties in the struts-config.xml. However, a word of warning, everything in the Request gets populated into this ActionForm circumventing the normal firewall function of Struts forms. Therefore you should only take out of this form properties you expect to be there rather than blindly populating all the properties into the business tier.

Having said that it is not necessary to pre-define properties in the struts-config.xml, it is useful to sometimes do so for mapped or indexed properties. For example, if you want to use a different Map implementation from the default HashMap or an array for indexed properties, rather than the default List type:


   <form-bean name="myForm" type="org.apache.struts.validator.LazyValidatorForm">
     <form-property name="myMap" type="java.util.TreeMap" />
     <form-property name="myBeans" type="org.apache.commons.beanutils.LazyDynaBean[]" />
   </form-bean>
 

Another reason for defining indexed properties in the struts-config.xml is that if you are validating indexed properties using the Validator and none are submitted then the indexed property will be null which causes validator to fail. Pre-defining them in the struts-config.xml will result in a zero-length indexed property (array or List) being instantiated, avoiding an issue with validator in that circumstance.

This implementation validates using the ActionForm name. If you require a version that validates according to the path then it can be easily created in the following manner:


    public class MyLazyForm extends LazyValidatorForm {

        public MyLazyForm () {
            super();
            setPathValidation(true);
        }

    }
 

Rather than using this class, another alternative is to either use a LazyDynaBean or custom version of LazyDynaBean directly. Struts now automatically wraps objects which are not ActionForms in a BeanValidatorForm. For example:


   <form-bean name="myForm" type="org.apache.commons.beanutils.LazyDynaBean">
     <form-property name="myBeans" type="org.apache.commons.beanutils.LazyDynaBean[]" />
   </form-bean>
 

Since:
Struts 1.2.6
Version:
$Rev: 56698 $ $Date: 2004-11-05 21:11:41 +0000 (Fri, 05 Nov 2004) $
See Also:
Commons BeanUtils JavaDoc, Serialized Form

Fields inherited from class org.apache.struts.validator.BeanValidatorForm
dynaBean, logger, pathValidation
 
Fields inherited from class org.apache.struts.validator.ValidatorForm
log, page, validatorResults
 
Fields inherited from class org.apache.struts.action.ActionForm
multipartRequestHandler, servlet
 
Constructor Summary
LazyValidatorForm()
          Default Constructor which creates a LazyDynaBean to back this form.
LazyValidatorForm(org.apache.commons.beanutils.DynaBean bean)
           
 
Method Summary
 java.lang.Object get(java.lang.String name, int index)
          Return an indexed property value.
 java.util.Map getMap()
          Return the Map containing the property values.
protected  org.apache.commons.beanutils.DynaBean newIndexedBean(java.lang.String name)
          Creates new DynaBean instances to populate an 'indexed' property of beans - defaults to LazyDynaBean type.
 
Methods inherited from class org.apache.struts.validator.BeanValidatorForm
contains, get, get, getDynaBean, getDynaClass, getInstance, getValidationKey, isPathValidation, remove, set, set, set, setPathValidation, size
 
Methods inherited from class org.apache.struts.validator.ValidatorForm
getPage, getResultValueMap, getValidatorResults, reset, setPage, setValidatorResults, validate
 
Methods inherited from class org.apache.struts.action.ActionForm
getMultipartRequestHandler, getServlet, getServletWrapper, reset, setMultipartRequestHandler, setServlet, validate
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

LazyValidatorForm

public LazyValidatorForm()
Default Constructor which creates a LazyDynaBean to back this form.

LazyValidatorForm

public LazyValidatorForm(org.apache.commons.beanutils.DynaBean bean)
Method Detail

get

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

Return an indexed property value.

If the "indexed" property is a List type then any missing values are populated with a bean (created in the newIndexedBean(name) method - in this implementation this is a LazyDynaBean type.

Overrides:
get in class BeanValidatorForm
Following copied from class: org.apache.struts.validator.BeanValidatorForm
Parameters:
name - Name of the property whose value is to be retrieved
index - Index of the value to be retrieved

getMap

public java.util.Map getMap()

Return the Map containing the property values.

Provided so that properties can be access using JSTL.


newIndexedBean

protected org.apache.commons.beanutils.DynaBean newIndexedBean(java.lang.String name)

Creates new DynaBean instances to populate an 'indexed' property of beans - defaults to LazyDynaBean type.

Override this method if you require a different type of DynaBean.



Copyright 2000-2006 - The Apache Software Foundation