Comrades,
Objective: To autopopulate forms on submit. The formbean "has a" collection of
collections of ValueObjects. Each valueObject contains a pair of other Value Objects.
Before people beat me up, The following possibilities have been dealt with:
1>> No, this is not a case of reset() I have the collections initialized and things
are fine.
2>> It is not a case of bean being in request scope. By default the bean is in session
scope (Unless we explicitly mention the action attribute that it is request scope.)
When asked about why the nested beans were not dynamically populated even though the
getter() methods are beling called, Nesting and Recursion Guru Arron Bates said the
following:
<quote>
FYI
This isn't a "nested tags" issue at all, but a nested bean-in-a-list
issue which Struts had a long time before I wrote the nested tags.
They're only guilty of making something quite complex very easy to do.
:)
Wrap your collections in org.apache.commons.collections.LazyList,
provide a class definition of your child bean and it'll be sweet and
ready to do without any other effort, even in the reset() method.
</quote>
So without wasting anytime, I downloaded the nightly build and incorporated it into my
IDE. I still seem to be missing something.
I wrote a simple method to "test" the wrapping. I get the following...
<trace>
java.lang.IllegalArgumentException: Null property value for 'wrappedCollections[0]'
java.lang.Throwable(java.lang.String)
java.lang.Exception(java.lang.String)
java.lang.RuntimeException(java.lang.String)
java.lang.IllegalArgumentException(java.lang.String)
java.lang.Object
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(java.lang.Object,
java.lang.String)
java.lang.Object
org.apache.commons.beanutils.PropertyUtils.getProperty(java.lang.Object,
java.lang.String)
java.lang.Object
org.apache.struts.util.RequestUtils.lookup(javax.servlet.jsp.PageContext,
java.lang.String, java.lang.String, java.lang.String)
int org.apache.struts.taglib.logic.IterateTag.doStartTag()
</trace>
<jspSnippet>
<nested:iterate id="voPairCollectionHolder" property="wrappedCollections"
name="rangesform" type="com.xxx.operations.mplanning.mpi.util.VoPairCollectionHolder">
<nested:iterate id="vopair" name="voPairCollectionHolder" property="voPairs"
type="com.xxx.operations.mplanning.mpi.util.ValueObjectPair">
.........................
.................................
<nested:write name="vopair" property="twVo.objectType"/> - <nested:write
name="vopair" property="twVo.description"/>
</jspSnippet>
public java.util.Collection generateWrappedCollection()
{
if (null != this.collectionOfCollectionsOfVoPairs)
{
ArrayList list = new ArrayList();
//This is the entire collection.
Iterator iterator = this.collectionOfCollectionsOfVoPairs.iterator();
//A LazyList
List lazyList = null;
ValueObjectPair voPair = new ValueObjectPair();
//A container for ValueObjectPair collection.
VoPairCollectionHolder holder = null;
while (iterator.hasNext())
{
//Gets each collection of ValueObject Pairs.
Collection voPairCollection = (Collection) iterator.next();
//Wrap collection containing ValueObjectPairs into a LazyList.
lazyList =
LazyCollections.lazyList(new ArrayList(voPairCollection),
voPair.getClass());
//Place each ValueObjectPair collection into a VoPairCollecitonHolder.
holder = new VoPairCollectionHolder(lazyList);
//The list now is a collection of VoPairCollection holders.
list.add(holder);
//list.add(lazyList);
}
//Now Wrap the collection of collections of valueobject pairs in another
lazylist
this.wrappedCollections = LazyCollections.lazyList(list, holder.getClass());
}
return this.wrappedCollections;
}
I am about to give up on form auto populate as I am out of time. I will be populating
them by hand but anyway... one last attempt. We dont like to lose... do we?
Thanks In Advance
hemant