I want to create my custom Java JSP tags for tree structure such as:
<ul>
<li>
<a href="#">Root</a>
<ul>
<li><a href="#">Node</a></li>
<li><a href="#">Node</a></li>
<li><a href="#">Node</a></li>
<li>
<a href="#">Node</a>
<ul>
<li><a href="#">Node</a></li>
<li><a href="#">Node</a></li>
</ul>
</li>
</ul>
</li>
</ul>
In JSP file an XML should looks like:
<lib:treeview>
<lib:treenode path="/some/path.do" label="Root">
<lib:treenode path="/some/path.do" label="NodeLabel"/>
<lib:treenode path="/some/path.do" label="NodeLabel"/>
<lib:treenode path="/some/path.do" label="NodeLabel"/>
</lib:node>
</lib:treeview>
Did somebody implement nested structures like this one? What classes are better to use? Maybe somebody has some useful links? Help, please :)
Haven't tested this, something like this should work:
treeview.tag:
<%@ tag description="treeview" %>
<ul>
<jsp:doBody />
</ul>
treenode.tag:
<%@ tag description="treenode" %>
<%@ attribute name="label" required="true" type="java.lang.String" %>
<%@ attribute name="path" required="true" type="java.lang.String" %>
<li>
<a href="${path}">${label}</a>
<jsp:doBody />
</li>
test.jsp:
<lib:treeview>
<lib:treenode label="root" path="#">
<lib:treeview>
<lib:treenode label="node" path="#">
<lib:treenode label="node" path="#">
<lib:treenode label="node" path="#">
</lib:treeview>
</lib:treenode>
</lib:treeview>
output:
<ul>
<li>
<a href="#">root</a>
<ul>
<a href="#">node</a>
<a href="#">node</a>
<a href="#">node</a>
</ul>
</li>
</ul>
This JSP tree is simple one. You can enhance. It has checkboxes as well. The complete source code and Read Me file will guide you. I have wrote this in my free time. Bye
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.