logo       

Velocity macros for recursive display of tree?: msg#00137

jakarta.velocity.user

Subject: Velocity macros for recursive display of tree?

Can anybody tell me if Velocity would be given to displaying recursive structures? From a brief skimming over the macro language, it appears this would be possible by having a macro call itself.

The problem I have is that I would like to display a tree structure (folders, files), but the web (or at least JSP) is a notoriously bad medium for something like this. My first cut with pure JSP was pretty painful. Just recently I wrote a generic custom tag to render trees, based on the javax.swing.tree package interfaces (TreeModel, TreeNode), but still, while being somewhat less painful, it is pretty ugly (basically the recursive descent logic is now replaced by the tag (which actually forces you to be iterative instead of recursive), but the display is still using embedded JSP).

The logic is something like:

<ul>
render: $node

if $node is a folder
<li>display $node folder details
if $node has children
<ul>
for each $node child
render($child)
end
</ul>
fi
</li>
else
display <li>$node file details</li>
fi
</ul>

of course there is a bit of logic in the display of the node, so I'd have to call out to methods on other classes.

TIA
Aaron


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise