tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Bayern <>
Subject Re: Looping a tree-structure of objects of unknown depth
Date Fri, 14 Feb 2003 14:19:11 GMT
On Fri, 14 Feb 2003, Sakke Wiik wrote:

> I have a tree-structure of objects similar to a filesystem, where
> directories has subdirectories to an unknown depth. How can i loop and
> display all these in jsp without knowing the depth of the tree? it's
> easy to do in pure java with a method calling itself, but I can't use
> methods inside a jsp, or can I?

You could define a method with a <%! ... %> declaration and use
scriptlets; Java and JSP are really the same thing.

But as a more interesting approach, you can think of each JSP page as a
method or component; you can write a JSP page to handle each directory and
then "call" it recursively with <jsp:include> each time you encounter a

In other words, for a hypothetical "file" object with boolean properties
like isFile() and isDirectory(), you could do the following:

  <c:forEach value="${requestScope.currentDir}" var="f">
      <c:when test="${f.file}">
        <c:out value="${}" /> <br />
      <c:when test="${}">
	      <b><c:out value="${}" /></b> <br />
              <jsp:include page="printDirectory.jsp" />

Cute, huh? :-)

Shawn Bayern
"JSTL in Action"

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message