用于嵌套树结构的 Java JSP 自定义标记。

发布于 2024-12-13 15:58:10 字数 1093 浏览 1 评论 0原文

我想为树结构创建自定义 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>

有人实现了像这样的嵌套结构吗?哪些类比较好用?也许有人有一些有用的链接?请帮忙:)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞旧 2024-12-20 15:58:10

还没有测试过这个,类似这样的东西应该可以工作:

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>

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>
瑾夏年华 2024-12-20 15:58:10

这棵 JSP 树很简单。你可以增强。它也有复选框。完整的源代码和自述文件将指导您。这是我在空闲时间写的。再见

http://sourceforge.net/projects/jsptree-simple/

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

http://sourceforge.net/projects/jsptree-simple/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文