• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array of arrays

 
Manuel Zapata
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"/>
</logic:iterate></logic:iterate>

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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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 ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic