You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/07/02 03:25:01 UTC

[Off Topic] Iterating through Parents/children help

Subject: [Off Topic] Iterating through Parents/children help
From: "Matt Raible" <ma...@raibledesigns.com>
 ===
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>