• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem adding dynamically a new element to an ArrayList

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Struts 1..?
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're still using 1.2.7...
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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

Thanks...
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try posting the relevant declarations, getters, and setters for your beans. The problem is probably there somewhere.
 
reply
    Bookmark Topic Watch Topic
  • New Topic