struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Nyberg" <greg.nyb...@objectpartners.com>
Subject RE: form bean with ArrayList
Date Thu, 25 Apr 2002 18:40:37 GMT
Thanks for looking in to this and for your response.

>From my experimentation, you actually have to loop through and create empty
elements in the ArrayList sufficient to hold the data being posted.
Neither:

control = new ArrayList(31);

nor:

control = new ArrayList();
control.ensureCapacity(31);

in the reset() method work properly. Only the loop:

control = new ArrayList();
for (int jj=0; jj<31; jj++) {
  control.add("");  // or new String()
}

creates the control list in a way which allows the PropertyUtil to post the
results without the range exception. Remember that I cannot intercept this
posting behavior in my setControl(Arraylist newvalue) method in the form
bean because, as a poster named Aaron mentioned, the utils never calls that
method.  It only calls getControl() to get the ArrayList reference and then
places data in the ArrayList directly using, as you found, set().. Not sure
I like that lack of encapsulation either, BTW.

As I said before, placing the form bean in the session is a hack (and is
inefficient in a cluster)..

-Greg

> -----Original Message-----
> From: Nicolas De Loof [mailto:nicolas.deloof@cgey.com]
> Sent: Thursday, April 25, 2002 7:24 AM
> To: Struts Users Mailing List
> Subject: Re: form bean with ArrayList
>
>
> > > That's pretty weird, considering an ArrayList has an initial
> capacity of
> 10
> > > and grows automatically.  Are you sure you are
> re-instantiating the List
> > > after (I assume) dereferencing it in reset()?
> >
> > This "grows automatically" part is something that I think is not
> > completely right. If you always call "add()" then OK, it grows
> > automatically. But try:
> >
> > ArrayList a = new ArrayList();
> > a.set(30, Boolean.TRUE);
> >
> > And you get an ArrayIndexOutOfBoundsException.
>
> What I can see in Struts code, is that PropertyUtil uses the
> java.beans.IndexedPropertyDescriptor class to set indexed
> properties values.
>
> On an ArrayList, the getIndexedWriteMethod() return the
> "set(int, Object)" Method, so this actually will not assume the List to
> increase it's size.
>
> I think you have to ensure manually the capacity of your List in your
> reset(). Perhaps you could use the preceding List instance (that
> was used to
> display the JSP) to get the collection size
>
> int size = control.size(); // list used to display Form
> control = new ArrayList(size); // list created to get user's datas
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>



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


Mime
View raw message