You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Teulings <ra...@edge.ping.de> on 2005/11/12 11:20:44 UTC
Iterating over a Collection of Collection of Bean
Hello!
I want to display a property in my *jsp that is of type Collection
(LinkedList) of Collection (LinkedList) of Bean - in principle a two
dimensional matrix of Beans.
I tried to use some code like
<logic:iterate id="categoryList" name="categories"
type="java.util.LinkedList">
X
<logic:iterate id="category" name="categoryList"
type="org.teulings.knowhow.bean.Category">
Y
</logic:iterate>
</logic:iterate>
but this does not work as the second iterate cannot see the iteration
variable of the first iterate (categoryList). Using similar "nested"
tags did not help either. I also look more closer at the "nested"
tutorials but they assume that I buil dmy datastructure all together
based on my beans.
I s there a way to use nested java collections or do I have to fall back
to building my own beans?
--
Gruß...
Tim.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Iterating over a Collection of Collection of Bean
Posted by Rasika <it...@yahoo.co.uk>.
Try this...
<logic:iterate id="category" name="categoryList"
type="org.teulings.knowhow.bean.Category"
property="property_of_X_that_is_a_list">
Tim Teulings wrote:
>
> Hello!
>
> I want to display a property in my *jsp that is of type Collection
> (LinkedList) of Collection (LinkedList) of Bean - in principle a two
> dimensional matrix of Beans.
>
> I tried to use some code like
>
> <logic:iterate id="categoryList" name="categories"
> type="java.util.LinkedList">
> X
> <logic:iterate id="category" name="categoryList"
> type="org.teulings.knowhow.bean.Category">
> Y
> </logic:iterate>
> </logic:iterate>
>
> but this does not work as the second iterate cannot see the iteration
> variable of the first iterate (categoryList). Using similar "nested"
> tags did not help either. I also look more closer at the "nested"
> tutorials but they assume that I buil dmy datastructure all together
> based on my beans.
>
> I s there a way to use nested java collections or do I have to fall back
> to building my own beans?
>
>
> --
> Gru?...
> Tim.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Iterating-over-a-Collection-of-Collection-of-Bean-tf538426.html#a7352467
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Iterating over a Collection of Collection of Bean
Posted by Laurie Harper <la...@holoweb.net>.
Tim Teulings wrote:
> Hello!
>
> I want to display a property in my *jsp that is of type Collection
> (LinkedList) of Collection (LinkedList) of Bean - in principle a two
> dimensional matrix of Beans.
>
> I tried to use some code like
>
> <logic:iterate id="categoryList" name="categories"
> type="java.util.LinkedList">
> X
> <logic:iterate id="category" name="categoryList"
> type="org.teulings.knowhow.bean.Category">
> Y
> </logic:iterate>
> </logic:iterate>
>
> but this does not work as the second iterate cannot see the iteration
> variable of the first iterate (categoryList). Using similar "nested"
> tags did not help either. I also look more closer at the "nested"
> tutorials but they assume that I buil dmy datastructure all together
> based on my beans.
>
> I s there a way to use nested java collections or do I have to fall back
> to building my own beans?
Works for me (see sample JSP below). Check your data structure actually
looks the way you think it does (i.e. that it's correctly populated).
L.
<%@ page import="java.util.List"%>
<%@ page import="java.util.LinkedList"%>
<%
String[][] data = new String[][] {
{ "a1", "a2", "a3" },
{ "b1", "b2", "b3" },
{ "c1", "c2", "c3" },
};
List outer = new LinkedList();
for (int i = 0; i < data.length; i++) {
java.lang.String[] strings = data[i];
List inner = new LinkedList();
for (int j = 0; j < strings.length; j++) {
String string = strings[j];
inner.add(string);
}
outer.add(inner);
}
pageContext.setAttribute("outer", outer);
%>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>
<logic:iterate id="inner" name="outer">
X
<logic:iterate id="bean" name="inner">
Y ${bean}
</logic:iterate>
<br/>
</logic:iterate>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org