You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brandon Goodin <ma...@phase.ws> on 2003/05/02 18:33:04 UTC

DynaActionForm and Collections of complex objects

I am strongly considering using DynaActionForms for some elements of my
struts app to introduce some needed flexibility. The one area I am not sure
about is in regards to populating values within a list of complex objects.

In the past when I have an indexed form element that populates the value of
a complex object in a collection property in my ActionForm I used the
following code...

==============================
jsp form
==============================

<html:text property="aObject[0].aProperty" />
<html:text property="aObject[1].aProperty" />
<html:text property="aObject[2].aProperty" />
<html:text property="aObject[3].aProperty" />

=============================
action form
=============================
public class MyActionForm {

// property
protected Collection myList;

// Constructor
// NOTE: the GenericFactory just uses reflection
// to instantiate an object
MyActionForm() {
  this.myList =
    ListUtils.lazyList(
      new ArrayList(),
      new GenericFactory("com.foo.MyObject"));
}


// setter
public void setMyList(Collection myList){
  this.myList = myList;
}

// getter
public Collection getMyList() {
  return this.myList;
}

}

I have never run across a circumstance where I knew what the size of the
collection was going to be. Therefore, I use the ListUtils.lazyList in my
ActionForm's constructor to populate my collection with the complex objects.
I do this so the index can successfully populate the value of the complex
object without throwing an IndexOutOfBoundsException.

How would I accomplish this with DynaActionForm without having to write a
custom List implementation that uses lazyList for every possible Collection
of objects I will need?

In other words. Using DynaActionForms, how can I prepopulate a Collection
with complex objects so that my index values will populate the objects
contained in the collection?

Brandon Goodin


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org