File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Array of arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Array of arrays" Watch "Array of arrays" New topic

Array of arrays

Manuel Zapata

Joined: Dec 14, 2006
Posts: 1
I have in the HttpServletRequest object an ArrayList of ArrayList. I'm using two logic:iterate tags to iterate over this collection, bu it doesn't wok. This is the source code:

<logic:iterate name="modificarPorcentajesForm" id="elemento" property="listaCategorias" indexId="index" scope="request">
<logic:iterate name="elemento" id="actividad" indexId="index2" type="co.notas.basica.Activity">
<html:text name="modificarPorcentajesForm" property='<%="elemento["+index+"].actividad["+index2+"].percentage"%>' size="3"/>

modificarPorcentajeForm is the object in the request and the property "listaCategorias" is the ArrayList of ArrayList. "percentage" is a property of the object "Activity". The error is the following:

No getter method for property elemento[0].actividad[0].percentage of bean modificarPorcentajesForm.

Thanks for any help you could give me.
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
May be this will work:

This will work provided your Activity Object has getter and setter methods for percentage variable.

[ December 15, 2006: Message edited by: Christian Nash ]

- Christian
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I've found that when using indexed properties, an ArrayList of Arraylists doesn't work very well. What I'd suggest is creating a custom object that contains an arraylist. That way you can add the requisite indexed getter to the object to make it work in this situation.

For example, you could create a Categoria class that has the following methods:

You could then make the ArrayList in your Action form contain a list of Categoria objects. The code you showed us above would now work as long as your ActionForm has the following method:

One more thing: If your ActionForm is in request scope, you will need to give your getters "lazy initialization" behavior in order to avoid getting "index out of range" errors when you submit the form. This link contains further detail. You will also find a working example of using indexed properties here.
[ December 15, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: Array of arrays
It's not a secret anymore!