problem adding dynamically a new element to an ArrayList
Kristof Camelbeke
Ranch Hand
Joined: Nov 28, 2001
Posts: 97
posted
0
Hello I don't know if this is the correct forum since it's a jsp-struts-javascript issue...
Anyway here's the situation.
A page is loaded with a form which contains a List....
This list is iterated as follows:
The properties of this list are stored and passed via <html:hidden> properties to the javascript function where the html code is generated.
Here's an example of the generated html output for 1 property:
All works well when I submit the form without adding a new element
When the the user decides to create a new element the same javascript function is called to create the html code indexing the proper form elements.
When the submit is done I get an ArrayOutOfBoundsException at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:433)
So how do you increment the list size? I use the getXXX(index) in my form but it never gets there when the index is larger thant the list size.
I've seen many examples but most are for editing the current list not adding new elements...
I have a getXX(index) method which is called for the existing items but I have no setter and that might be the problem for the ArrayIndexOutOfBoundsException as mentionned in the article:
The indexed getter and setter methods may throw a java.lang.ArrayIndexOutOfBoundsException runtime exception if an index is used that is outside the current array bounds. In order to change the size of the array you must use the array setter method to set a new (or updated) array.
Kristof Camelbeke wrote:
I'll try this first out thing monday morning...
why monday?.
Kristof Camelbeke
Ranch Hand
Joined: Nov 28, 2001
Posts: 97
posted
0
It's on my pc at work and since they don't give us laptops I don't have any other option than to wait till monday morning
Kristof Camelbeke
Ranch Hand
Joined: Nov 28, 2001
Posts: 97
posted
0
I've added the indexed setters/getters on my bean but they never get called... I even added them on the ActionForm but also no result....
here's the generated html output:
To resume my 'aDto' has a List 'aList' wich references Object items where serial number is a String property.
I've added indexed getter/setters in this dto for the list and for the properties of the Object items but they never get called.
When debugging I see that the public Object getIndexedProperty(Object bean, String name) method is called from the PropertyUtilsBean and that the line return (getIndexedProperty(bean, name, index)); contains the bean with index 2 and the index 3 which causes the ArrayOutOfBoundsExcption....
Kristof Camelbeke
Ranch Hand
Joined: Nov 28, 2001
Posts: 97
posted
0
Hello,
Anybody has an idea what the cause of this problem is?
Thanks...
Tom Rispoli
Ranch Hand
Joined: Aug 29, 2008
Posts: 349
posted
0
try posting the relevant declarations, getters, and setters for your beans. The problem is probably there somewhere.