FAQ
Hi all,

I?m trying to receive a filled array of objects. In struts-config:

<form-property name="myAttribute" type="br.mypackage.MyClass[]"/>


In HTML file:

<input type="text" name="myAttribute[0].myNestedAttribute">

When I try to submit a form with these configurations, the following expection
is thrown:

java.lang.ArrayIndexOutOfBoundsException
at java.lang.reflect.Array.get(Native Method)
at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:250)
at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:386)
.
.
.

How can I fill an indexed java object using Struts ?


thanks in advance,

Sergio Stateri Jr.
sergio.stateri@globo.com



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

Search Discussions

  • Laurie Harper at Sep 5, 2007 at 9:50 pm

    Sergio Stateri Jr wrote:
    Hi all,

    I?m trying to receive a filled array of objects. In struts-config:

    <form-property name="myAttribute" type="br.mypackage.MyClass[]"/>


    In HTML file:

    <input type="text" name="myAttribute[0].myNestedAttribute">

    When I try to submit a form with these configurations, the following expection
    is thrown:

    java.lang.ArrayIndexOutOfBoundsException
    at java.lang.reflect.Array.get(Native Method)
    at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:250)
    at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:386)
    ..
    ..
    ..

    How can I fill an indexed java object using Struts ?
    You need to make sure the myAttribute array is initialized with enough
    entries before the form data is put into it, or allocate additional
    entries as needed during population.

    You'll need to create a form class (you can extend DyanaActionForm) and
    either (a) create the empty array at the appropriate length in the
    reset() method:

    myAttribute = new MyClass[SIZE];

    or, if you don't know what SIZE will be before receiving the form data,
    you can (b) create a setter for myAttribute that automatically 'grows'
    the array as needed.

    Search the archives for examples of the latter technique; there are a
    few approaches that work well.

    L.


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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesstruts
postedAug 31, '07 at 10:08p
activeSep 5, '07 at 9:50p
posts2
users2
websitestruts.apache.org
irc#struts

People

Translate

site design / logo © 2022 Grokbase