struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas De Loof" <nicolas.del...@cgey.com>
Subject Re: form bean with ArrayList
Date Thu, 25 Apr 2002 12:23:46 GMT
> > 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>


Mime
View raw message