You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hunter Hillegas <li...@lastonepicked.com> on 2003/05/14 20:37:49 UTC

Problem Using Nested and ArrayList

I have an ArrayList in an ActionForm that holds "line items" for me.

The number of these "line items" in the ArrayList is dynamic.

I am having a problem when submitting the ActionForm to Struts. Basically I
get an IndexOutOfBoundsException. It seems that when Struts is instantiating
the form, it is expecting the ArrayList to already have a pre-allocated
number of Objects as there are line items...

So instead of adding these line item forms as new elements to the ArrayList,
is is expecting to use set()?

Anyway, I'm confused. Should I be pre-filling this ArrayList with bogus
"line items" and then letting Struts insert the real values? If so, what is
the best way to do this, since the number of these line items is dynamic and
changes with each request (user specifies number).

Thanks,
Hunter


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


Re: Problem Using Nested and ArrayList

Posted by Hunter Hillegas <li...@lastonepicked.com>.
Sure. Thanks. Please let me know if I am doing something incorrectly. This
is my first Struts application.

public class SampleRequestBodyForm extends ActionForm {
...snip...
ArrayList lineItems; //sample request line item forms
    
public SampleRequestBodyForm() {
    System.out.println("SampleRequestBodyForm - Constructor Called");
    lineItems = new ArrayList();
}

public ArrayList getLineItems() {
System.out.println("Accessing line items. Contains: " + lineItems.size());
return lineItems;
}
}

I snipped out a bunch, but I think I left the relevant stuff.

Here's what I see in my log:

11:35:58,789 INFO  [STDOUT] SampleRequestBodyForm - Constructor Called
11:35:58,795 INFO  [STDOUT] Accessing line items. Contains: 0
11:35:58,801 WARN  [jbossweb] WARNING: Exception for
/jake_intranet/CreateSampleRequest.do
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:508)
        at java.util.ArrayList.get(ArrayList.java:320)
        at 
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.
java:521)
        at 
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.
java:428)
        at 
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.j
ava:770)
        at 
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:80
1)
        at 
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
        at 
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
        at 
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1096)
        at 
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.j
ava:816)
        at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
        at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420)
        at 
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
        at 
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandl
er.java:294)
        at 
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
        at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
        at 
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext
.java:507)
        at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
        at org.mortbay.http.HttpServer.service(HttpServer.java:863)
        at org.jboss.jetty.Jetty.service(Jetty.java:460)
        at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
        at 
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
        at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
        at 
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
        at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
        at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)


> From: "Mark Galbreath" <ma...@qat.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Wed, 14 May 2003 14:47:06 -0400
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Subject: RE: Problem Using Nested and ArrayList
> 
> Let's see the relevant code in your ActionForm with line numbers and the
> actual stack trace.
> 
> Mark
> 
> -----Original Message-----
> From: Hunter Hillegas [mailto:lists@lastonepicked.com]
> Sent: Wednesday, May 14, 2003 2:38 PM
> To: Struts List
> Subject: Problem Using Nested and ArrayList
> 
> 
> I have an ArrayList in an ActionForm that holds "line items" for me.
> 
> The number of these "line items" in the ArrayList is dynamic.
> 
> I am having a problem when submitting the ActionForm to Struts. Basically I
> get an IndexOutOfBoundsException. It seems that when Struts is instantiating
> the form, it is expecting the ArrayList to already have a pre-allocated
> number of Objects as there are line items...
> 
> So instead of adding these line item forms as new elements to the ArrayList,
> is is expecting to use set()?
> 
> Anyway, I'm confused. Should I be pre-filling this ArrayList with bogus
> "line items" and then letting Struts insert the real values? If so, what is
> the best way to do this, since the number of these line items is dynamic and
> changes with each request (user specifies number).
> 
> Thanks,
> Hunter
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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


RE: Problem Using Nested and ArrayList

Posted by Mark Galbreath <ma...@qat.com>.
Let's see the relevant code in your ActionForm with line numbers and the
actual stack trace.

Mark

-----Original Message-----
From: Hunter Hillegas [mailto:lists@lastonepicked.com] 
Sent: Wednesday, May 14, 2003 2:38 PM
To: Struts List
Subject: Problem Using Nested and ArrayList


I have an ArrayList in an ActionForm that holds "line items" for me.

The number of these "line items" in the ArrayList is dynamic.

I am having a problem when submitting the ActionForm to Struts. Basically I
get an IndexOutOfBoundsException. It seems that when Struts is instantiating
the form, it is expecting the ArrayList to already have a pre-allocated
number of Objects as there are line items...

So instead of adding these line item forms as new elements to the ArrayList,
is is expecting to use set()?

Anyway, I'm confused. Should I be pre-filling this ArrayList with bogus
"line items" and then letting Struts insert the real values? If so, what is
the best way to do this, since the number of these line items is dynamic and
changes with each request (user specifies number).

Thanks,
Hunter


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



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