You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jean michel corne <jm...@spiderbusiness.com> on 2004/07/27 10:22:49 UTC
DynaActionForm and ArrayList : IndexOutOfBoundsException
Hi Struts users,
I have tried to use ArrayList in the DynaActionForm with Struts 1.1.
Before the action is processed (processActionForm), I got an error:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(ArrayList.java:507)
java.util.ArrayList.get(ArrayList.java:324)
org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:298)
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:474)
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
struts-config.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="CalendarForm" type="fr.sipe.test.forms.CalendarForm" />
<form-bean name="purchaseOrderBeanForm" type="org.apache.struts.validator.DynaValidatorForm"><!-- org.apache.struts.action.DynaActionForm-->
<form-property name="lines" type="fr.sipe.test.forms.POLine[]" size="4" />
<form-property name="arrayLines" type="java.util.ArrayList" size="4" />
</form-bean>
</form-beans>
<!-- ========== Global Exception Definitions ============================== -->
<global-exceptions />
<!-- ========== Global Forward Definitions =============================== -->
<global-forwards type="org.apache.struts.action.ActionForward">
<forward name="calendarStyle" path="/css/calendar.css" />
<forward name="calendarJs" path="/js/calendar.js" />
<forward name="error" path="/error.jsp" />
</global-forwards>
<!-- ========== Action Mapping Definitions =============================== -->
<action-mappings type="org.apache.struts.action.ActionMapping">
<action
input="/calendar.jsp"
name="CalendarForm"
path="/ViewCalendar"
scope="request"
type="fr.sipe.test.actions.ViewCalendarAction" >
<forward name="Success" path="/calendar.jsp" />
</action>
<action
path="/generateBeanPOForm"
input="/purchaseOrderBean.jsp"
type="fr.sipe.test.actions.GenerateBeanPOForm"
name="purchaseOrderBeanForm"
scope="request" >
<forward name="success" path="/purchaseOrderBean.jsp" redirect="false"/>
</action>
<action
path="/generateBeanPO"
type="fr.sipe.test.actions.GenerateBeanPO"
name="purchaseOrderBeanForm"
scope="request"
input="/purchaseOrderBean.jsp">
<forward name="success" path="/displayPurchaseOrderBean.jsp" redirect="false"/>
</action>
</action-mappings>
<message-resources parameter="resources.application" null="false" />
<controller processorClass="org.apache.struts.action.RequestProcessor" contentType="text/html"/>
</struts-config>
I'ved download the source code and traced the calls. The method that returns this error is located in the class
BeanUtils.setProperty(Object bean, String name, Object value)
At the call: target = PropertyUtils.getProperty(bean, name.substring(0, delim));
The bean is created but the size of the ArrayList is 0, so when calling the first property at indexed 0, I got an error.
Do you have any idea how to solve this problem (without using POJO array like myBean[])?
Thanks for your help
Jean-Michel
RE: DynaActionForm and ArrayList : IndexOutOfBoundsException
Posted by Robert Taylor <rt...@mulework.com>.
This problem has been discussed many times on this list.
I recommend you search the archives.
In the mean time, have a look at using a lazy list.
http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/ListUtils.html#lazyList(java.ut
il.List,%20org.apache.commons.collections.Factory)
You can place the lazy list invocation in the forms reset() so
that a new lazy list gets created upon each call to reset().
In short the lazy list will use a designated factory to create
an object an populate a list whose indexed location is null.
There are other solutions as well.
hth,
robert
> -----Original Message-----
> From: jean michel corne [mailto:jmcorne@spiderbusiness.com]
> Sent: Tuesday, July 27, 2004 4:23 AM
> To: user@struts.apache.org
> Subject: DynaActionForm and ArrayList : IndexOutOfBoundsException
>
>
> Hi Struts users,
>
> I have tried to use ArrayList in the DynaActionForm with Struts 1.1.
>
> Before the action is processed (processActionForm), I got an error:
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> java.util.ArrayList.RangeCheck(ArrayList.java:507)
> java.util.ArrayList.get(ArrayList.java:324)
> org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:298)
> org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:474)
> org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
> org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
> org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
> org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
> org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
> org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
> org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
> org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
> org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
>
>
> struts-config.xml :
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
> "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
> <struts-config>
>
> <!-- ========== Form Bean Definitions ================================== -->
> <form-beans>
> <form-bean name="CalendarForm" type="fr.sipe.test.forms.CalendarForm" />
> <form-bean name="purchaseOrderBeanForm" type="org.apache.struts.validator.DynaValidatorForm"><!--
> org.apache.struts.action.DynaActionForm-->
> <form-property name="lines" type="fr.sipe.test.forms.POLine[]" size="4" />
> <form-property name="arrayLines" type="java.util.ArrayList" size="4" />
> </form-bean>
> </form-beans>
>
> <!-- ========== Global Exception Definitions ============================== -->
> <global-exceptions />
>
> <!-- ========== Global Forward Definitions =============================== -->
> <global-forwards type="org.apache.struts.action.ActionForward">
> <forward name="calendarStyle" path="/css/calendar.css" />
> <forward name="calendarJs" path="/js/calendar.js" />
> <forward name="error" path="/error.jsp" />
> </global-forwards>
>
> <!-- ========== Action Mapping Definitions =============================== -->
> <action-mappings type="org.apache.struts.action.ActionMapping">
> <action
> input="/calendar.jsp"
> name="CalendarForm"
> path="/ViewCalendar"
> scope="request"
> type="fr.sipe.test.actions.ViewCalendarAction" >
> <forward name="Success" path="/calendar.jsp" />
> </action>
>
> <action
> path="/generateBeanPOForm"
> input="/purchaseOrderBean.jsp"
> type="fr.sipe.test.actions.GenerateBeanPOForm"
> name="purchaseOrderBeanForm"
> scope="request" >
> <forward name="success" path="/purchaseOrderBean.jsp" redirect="false"/>
> </action>
>
> <action
> path="/generateBeanPO"
> type="fr.sipe.test.actions.GenerateBeanPO"
> name="purchaseOrderBeanForm"
> scope="request"
> input="/purchaseOrderBean.jsp">
> <forward name="success" path="/displayPurchaseOrderBean.jsp" redirect="false"/>
> </action>
> </action-mappings>
>
> <message-resources parameter="resources.application" null="false" />
>
> <controller processorClass="org.apache.struts.action.RequestProcessor" contentType="text/html"/>
> </struts-config>
>
>
>
> I'ved download the source code and traced the calls. The method that returns this error is located in the class
> BeanUtils.setProperty(Object bean, String name, Object value)
> At the call: target = PropertyUtils.getProperty(bean, name.substring(0, delim));
>
> The bean is created but the size of the ArrayList is 0, so when calling the first property at indexed 0, I got an error.
>
> Do you have any idea how to solve this problem (without using POJO array like myBean[])?
>
> Thanks for your help
> Jean-Michel
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org