I've seen two ways of dealing w/ this problem, both of which I see as 'hackish'
in nature.

Solution A:

In your getters/setters you implement the following code

public MyCustomBean getMyCustomBean(int index) {
   while(index >= myCustomBeanList.size()) {
      myCustomBeanList.add(new MyCustomBean());
   }
   return (MyCustomBean)myCustomBeanList.get(index);
}

In that way you'll never encounter the common IndexOutOfBoundsException.  The
problem here is that you tend to use alot of hidden fields in your UI to repopulate
the data back into the dynamically created beans.

Solution B:

In your reset() method you repopulate your internal Collection of beans.  The
problem w/ this approach is that often times you have a separate Action that
prepopulates your ActionForm.  This provides for good separation - the Action
is a retriever of a data (nothing more) and the ActionForm is merely a container
for data (nothing more).  With this approach your ActionForm suddenly starts
becoming more intelligent than it really should be.  Now it's aware of how to
populate itself...not a good thing IMO.

I'd be very interested in hearing other solutions to this problem as I find
both of the above solutions cumbersome and hackish and would love to stop implementing
them.

>I've been struggling with a problem similar to the one described (and
>solved) at
>http://www.mail-archive.com/[EMAIL PROTECTED]/msg50901.html .

>Is this really the recommended way to solve population / repopulation of
>properties stored in a List() of
>whatever-data-object-i-need-in-the-form-of-a-bean ? Is there a better way to

>acheive the same result ? (I.e represent a collection in a form)
>
>I've read that a practice often used to represent collections (a DB-table
>for intstance) is to make a bean that has getters / setters for the
>properties of a single row and then have the ActionForm contain a List() of

>those beans. One for every row  (in the DB-example). That far I can follow,

>and see how / why. But is there no better way to update the values in the
>ActionForm (beans) when the data is submitted than in the URL above ?
>
>//Linus Nikander - [EMAIL PROTECTED]
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>



John M. Corro
Cornerstone Consulting

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to