Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying tree on JSP page

I need to display tree on JSP page. How can I do that? I have following object:

public class Node {
    private Long id;
    private Long parentId;
    private String name;
    private List<Node> children;

    // Getters & setters

}
like image 442
newbie Avatar asked Jan 09 '11 10:01

newbie


2 Answers

Roll your own with jsp recursion

In Controller.java

Node root = getTreeRootNode();
request.setAttribute("node", root);

In main.jsp page

<jsp:include page="node.jsp"/>

In node.jsp

<c:forEach var="node" items="${node.children}">
    <!-- TODO: print the node here -->
    <c:set var="node" value="${node}" scope="request"/>
    <jsp:include page="node.jsp"/>
</c:forEach>

Based on http://web.archive.org/web/20130509135219/http://blog.boyandi.net/2007/11/21/jsp-recursion/

like image 73
Leif Gruenwoldt Avatar answered Oct 15 '22 16:10

Leif Gruenwoldt


You may want to try http://www.soft82.com/download/windows/tree4jsp/

It is also downloadable from http://www.einnovates.com/jsptools/tree4jsp/tree4jsp_v1.2.zip

like image 1
Sajad Avatar answered Oct 15 '22 16:10

Sajad