我想为树结构创建自定义Java JSP标记,例如:
<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>
在JSP文件中,XML应如下所示:
<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>
有人实现了像这样的嵌套结构吗?什么类更好用?也许有人有一些有用的链接?请帮助:)
答案 0 :(得分:1)
没有测试过,这样的事情应该有效:
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>
输出:
<ul>
<li>
<a href="#">root</a>
<ul>
<a href="#">node</a>
<a href="#">node</a>
<a href="#">node</a>
</ul>
</li>
</ul>
答案 1 :(得分:0)
这个JSP树很简单。你可以增强。它也有复选框。完整的源代码和自述文件将指导您。我在空闲时间写过这篇文章。再见