Subject: Re: [Off Topic] Iterating through Parents/children help [SOLVED] From: "Matt Raible" <[EMAIL PROTECTED]> === First page: -------------------
<c:forEach var="catalog" items="${libraryCatalog}"> <c:out value="${catalog.name}"/><br/> <%-- Show all the items in this catalog --%> <c:forEach var="link" items="${catalog.items}" varStatus="status"> <c:out value="${link.name}"/><br/> </c:forEach> <c:set var="catalogs" value="${catalog.catalogs}" scope="request"/> <c:set var="indentLevel" scope="request">40</c:set> <c:import url="/items.jsp"/> </c:forEach> Second Page (items.jsp): ------------------- <c:forEach var="catalog" items="${requestScope.catalogs}"> <c:out value="${catalog.name}"/> <%-- Show all the items in this catalog --%> <c:forEach var="link" items="${catalog.items}" varStatus="status"> <%-- determine if we're on an odd row --%> <c:out value="${link.name}"/></a> </c:forEach> <%-- include this same page again, with new values --%> <c:set var="catalogs" value="${catalog.catalogs}" scope="request"/> <c:set var="indentLevel" value="${requestScope.indentLevel + 20}" scope="request"/> <c:import url="/items.jsp"/> </c:forEach> "Matt Raible" <[EMAIL PROTECTED]> wrote in message news:afsg27$oee$[EMAIL PROTECTED]... > Here's what I came up with using JSTL, but there's GOT to be a better > (recursive) way of doing this: > > <c:forEach var="catalog" items="${myCatalog}"> > <c:out value="${catalog.name}"/><br/> > <%-- Show all the items in this catalog --%> > <c:forEach var="link" items="${catalog.items}"> > <c:out value="${link.name}"/> > </c:forEach> > > <%-- show all the child catalogs for this catalog --%> > <c:forEach var="child1" items="${catalog.catalogs}"> > <c:out value="${child1.name}"/> > > <%-- Show all the items in this catalog --%> > <c:forEach var="link" items="${child1.items}"> > <c:out value="${link.name}"/></a> > </c:forEach> > > <%-- show all the child catalogs for this catalog --%> > <c:forEach var="child2" items="${child1.catalogs}"> > <c:out value="${child2.name}"/> > > <%-- Show all the library items in this catalog --%> > <c:forEach var="link" items="${child2.items}" > varStatus="status"> > <c:out value="${link.name}"/> > </c:forEach> > > <%-- show all the child catalogs for this catalog --%> > <c:forEach var="child3" items="${child2.catalogs}"> > <c:out value="${child3.name}"/> > > <%-- Show all the items in this catalog --%> > <c:forEach var="link" items="${child3.items}" > varStatus="status"> > <c:out value="${link.name}"/> > </c:forEach> > </c:forEach> > </c:forEach> > </c:forEach> > </c:forEach> > > "Matt Raible" <[EMAIL PROTECTED]> wrote in message > news:afquue$811$[EMAIL PROTECTED]... > > I have an difficult architecture problem. Please help if you can. Below > > are two tables that are linked by catalog_id. > > > > catalog > > -------------- > > catalog_id > > catalog_name > > parent_id > > > > catalog_detail > > --------------- > > detail_id > > catalog_id > > detail_name > > detail_description > > detail_url > > > > > > So basically, these two tables are used to render the following in the > > "view" > > > > My First Catalog Entry > > -- URL to detail Entry > > -- URL to detail Entry > > > > My Second Catalog Entry > > -- URL to detail Entry > > > > ... you get the picture. > > > > My problem comes in in that a catalog entry can be a child of another > > catalog entry (not a detail entry). So you'd end up with something like > > this: > > > > My First Catalog Entry > > -- 1 > > -- 2 > > My Second Catalog Entry > > -- 3 > > -- > > My Third Catalog Entry.... > > > > I need help with (1) How do I prepare this data for display on a page, and > > (2) How do I design my page without knowing how many levels deep to go? > > > > Here are my solutions to date: > > > > 1. I query the catalog table, and create an ArrayList of CatalogForm's > > (JavaBeans). As I'm adding a CatalogForm to the arraylist, I use the > > catalog_id to get the children of that catalog entry and set them as a > > Vector of DetailForm's on the CatalogForm. This works great without the > > parent concept. With the parent concept, maybe I should keep what I'm > > doing, but then lookup through the ArrayList and see if any CatalogForm's > > have parents. If so, set the CatalogForm as a ChildForm on it's parent. > > > > 2. Use JSTL and <c:forEach> to iterate through the catalogForm's and > > display the name and the detail's information. I can add a few more > > <c:forEach> tags, but this will only allow the architecture to traverse > the > > number of levels that I've defined in my JSP. Is there anyway to allow > for > > infinite levels? Maybe some sort of reflection - or even using XML and > XSL? > > Any and all ideas are welcome. > > > > Finally, I am only responsible for displaying this data, nothing has to be > > updated - that's up to another application that's already been written. > > > > Thanks, > > > > Matt > > > > > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>