velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Priatel <>
Subject RE: tree structure
Date Mon, 16 Jul 2001 20:15:31 GMT
What I've done in the case of showing a thread tree in a message forum is to
create a tree object, then make the tree implement Iterator.  Your iterator
implementation should return tree nodes in a depth-first (uh...I think
that's the right term) fashion so that each call to next() returns nodes
from left to right, top to bottom.

Afterwards, your tree, given a node, should be able to tell you what that
node's depth is ( or add aa depth property to your node so that you can
create proper indentation)...Any rate, here's my velocity template (you can
see this in action at:
(bottom of page), as an example..)

Hope if helps...


<!-- Begin forum_thread_snapshot -->
<hr size=1 noshade>
<b>Message Thread</b>
#set($MAX = 8)   #* max levels of indentation *#
<table width=400 border=0 cellpadding=0 cellspacing=0>
#foreach( $i in [1..$MAX])
<td width=10><img src=/DT/images/spacer.gif width=10 height=1></td>
 <td width=100%></td>

#foreach( $node in $tree.getTreeIterator() )
 #set($m = $node.getValue()) #* msg subject *#
 #set($d = $tree.getDepth($node)) #*
 #set($diff = $MAX - $d + 1 )
 #if($d > $MAX) #set($d = $MAX) #end
 #if($d != 0)
    #foreach($i in [1..$d])
      <td> </td>
    <td colspan=$diff>
    <a href=$context/forum/viewmsg/msg-$m.getID()>$m.getSubject()</a>
    #if($m.getID() == $msg.getID()) (viewed) #end 

<hr size=1 noshade>

<!-- End forum_thread_snapshot -->

-----Original Message-----
From: Uday Kumar []
Sent: Monday, July 16, 2001 3:19 PM
Subject: tree structure

hi guys

i wanna know if any one of u has already implemented a tree structure
(similar to windows explorer, atleast indentation, if not collapsing and
expanding) in velocity? i mean if i have a vector thru which i need to loop
using foreach and print out as a tree.


----- Original Message -----
From: "Jon Stevens" <>
To: "velocity-user" <>
Sent: Monday, July 16, 2001 12:11 PM
Subject: Re: Can I write a macro that can call itself?

> on 7/14/01 6:15 AM, "Brad Cox" <> wrote:
> > And he wonders why more people don't pitch in to help. Sigh.
> I don't wonder that.
> -jon

View raw message