Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem adding dynamically a new element to an ArrayList

 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

Any input is mostly appreciated!

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this appears to be an issue populating a Struts form, I've moved it along to the Struts forum.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Struts 1..?
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're still using 1.2.7...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your bean set up properly to accept indexed properties? The rules are fairly stringent.

Here's something I found That might give you a wedge to start exploring...
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for the link to the article.

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.


I'll try this first out thing monday morning...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kristof Camelbeke wrote:
I'll try this first out thing monday morning...


why monday?.
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Anybody has an idea what the cause of this problem is?

Thanks...
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try posting the relevant declarations, getters, and setters for your beans. The problem is probably there somewhere.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic