Jsp Taglib for recursion

Y

yzzzzz

Hi,

I have this interface:

public interface A {
public String getTitle();
public List<A> getChildren();
}

I have an object of type A (root), which has children of type A, who
themselves have children, and so on.

In my JSP I would like do display a tree, e.g.

${root.title}
<ul>
<c:forEach items="${root.children}" var="element">
<li>${element.title}
<ul>
<c:forEach items="${element.children}" var="element2">
<li>${element2.title}
<ul>
<c:forEach items="${element2.children}" var="element3">
*** etc. ***
</c:forEach>
</ul>
</li>
</c:forEach>
</ul>
</li>
</c:forEach>
</ul>

Here I only have 3 levels of recursion. I need to display the whole
tree. Is there a way of doing this?


Thanks.
 
R

Ryan Stewart

yzzzzz said:
Hi,

I have this interface:

public interface A {
public String getTitle();
public List<A> getChildren();
}

I have an object of type A (root), which has children of type A, who
themselves have children, and so on.

In my JSP I would like do display a tree, e.g.

${root.title}
<ul>
<c:forEach items="${root.children}" var="element">
<li>${element.title}
<ul>
<c:forEach items="${element.children}" var="element2">
<li>${element2.title}
<ul>
<c:forEach items="${element2.children}" var="element3">
*** etc. ***
</c:forEach>
</ul>
</li>
</c:forEach>
</ul>
</li>
</c:forEach>
</ul>

Here I only have 3 levels of recursion. I need to display the whole
tree. Is there a way of doing this?
Recursion means a function that calls itself. What you have there isn't
technically recursion, but what you need is. If you're using JSP 2.0, you could
create an EL function:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html#wp77078

If not, you could probably get the same effect from a custom tag library with a
bit more work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top