struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Iterating over a Collection of Collection of Bean
Date Sun, 13 Nov 2005 01:20:08 GMT
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


Mime
View raw message