Kde*_*per 12
下面是一个递归标记文件的示例,该文件从节点中递归显示其所有子节点(用于生成YUI树视图):
/WEB-INF/tags/nodeTree.tag:
<%@tag description="display the whole nodeTree" pageEncoding="UTF-8"%>
<%@attribute name="node" type="com.myapp.Node" required="true" %>
<%@taglib prefix="template" tagdir="/WEB-INF/tags" %>
<li>${node.name}
<c:if test="${fn:length(node.childs) > 0}">
<ul>
<c:forEach var="child" items="${node.childs}">
<template:nodeTree node="${child}"/>
</c:forEach>
</ul>
</c:if>
</li>
Run Code Online (Sandbox Code Playgroud)
这可以在常规的JSP文件中使用,如下所示:
<div id="treeDiv1">
<ul>
<c:forEach var="child" items="${actionBean.rootNode.childs}">
<template:nodeTree node="${child}"/>
</c:forEach>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)