velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Hamid <ar...@cornell.edu>
Subject Velocity macros for recursive display of tree?
Date Wed, 20 Nov 2002 20:48:21 GMT
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


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message