If you used the database to help you out you could output the results with a
simple loop and then you would know the depth to place each item at.
However, this highly depends on what the information your storing is used
for, this does not work well for every case.

For instance you would have the following columns in your "category" table.
Parent_ID, Depth, Lineage where parentID references categoryID, depth starts
as null and lineage is a string. This also lets you sort the columns in
ascending order, and simplifies some of your indexing.

MS SQL Article, but the concept still applies 
http://www.sqlteam.com/item.asp?ItemID=8866

What this gives you is something similiar to .....

CategoryID      Category                Parent_ID       Depth           Lineage
1       Fruit           0       0               001
2       Apples          1       1               001.001
3       Green Apples    2       2               001.001.001
4       Red Apples              2       2               001.001.002
5       Crab Apples     4       3               001.001.002.001




Matt Raible-3 wrote:
> 
> You could probably use JSTL's <c:forEach> to traverse the tree and
> print out the contents. Regular ol' HTML tags should help you indent
> it where you need to.
> 
> Matt
> 
> On 1/23/07, Jonathan Tse <[EMAIL PROTECTED]> wrote:
>> Hi all,
>>
>>     I am implementing a multi-level hierarchy (You can imagine it
>> category , sub category and sub sub category). I want to output the
>> structure with indentation but still cannot find a good solution. Let's
>> ignore how the DAO retrieve the data first(another complication here).
>> Suppose I got an category POJO like this:
>>
>>     Class Category
>>     private int categoryId ;
>>     private List subCategoryList;
>>
>>     Each object inside subCategoryList is a Category object (Assume the
>> whole tree is retrieved for the sake of simplicity). Therefore, it means
>> that I need to read it recursively in the JSP if I just pass the root
>> node to the View. I couldn't find any tag library on the net that could
>> traverse the whole tree. Any idea?  Should I write a custom tag? Or just
>> flatten the structure before output to View?
>>
>> Best regards,
>> Jonathan Tse
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> -- 
> http://raibledesigns.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Recursive-data-structure-in-JSP-tf3062754s2369.html#a8521893
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to