treeexpandselect.jsp
来自「部门结构树」· JSP 代码 · 共 175 行
JSP
175 行
<%@ page import="com.jenkov.prizetags.tree.impl.TreeNode,
com.jenkov.prizetags.tree.impl.Tree,
com.jenkov.prizetags.tree.itf.*" %>
<%@ taglib uri="/WEB-INF/treetag.tld" prefix="tree" %>
<%@ taglib uri="/WEB-INF/requesttags.tld" prefix="request" %>
<%
if(session.getAttribute("example") == null){
//creating a simple tree model instance
ITree tree = new Tree();
tree.setSingleSelectionMode(true);
//adding server side event listeners to the tree model instance
//use these to build the tree dynamically.
tree.addExpandListener(new IExpandListener(){
public void nodeExpanded(ITreeNode node, ITree tree){
System.out.println("node " + node.getName() + " was expanded");
}
});
tree.addCollapseListener(new ICollapseListener(){
public void nodeCollapsed(ITreeNode node, ITree tree){
System.out.println("node " + node.getName() + " was collapsed");
}
});
//adding tree nodes in a tree structure to the tree model instance.
ITreeNode movies = new TreeNode("moviesId" , "Movies" , "movies");
ITreeNode thrillers = new TreeNode("thrillersId" , "Thrillers" , "thrillers");
ITreeNode thrillersNew = new TreeNode("newThrillId" , "New Thrillers", "newThrill");
ITreeNode thrillersOld = new TreeNode("oldThrillId" , "Old Thrillers", "oldThrill");
ITreeNode fantasy = new TreeNode("fantasyId" , "Fantasy" , "fantasy");
ITreeNode comedy = new TreeNode("comedyId" , "Comedies" , "comedies");
ITreeNode cartoons = new TreeNode("cartoonsId" , "Cartoons" , "cartoons");
ITreeNode comedySub = new TreeNode("comedySubId" , "Comedy Sub" , "comedies");
ITreeNode comedySubSub = new TreeNode("comedySubSubId" , "Comedy Sub Sub","comedies");
ITreeNode basicInstinct = new TreeNode("basicInstinctId" , "Basic Instinct" , "thriller");
ITreeNode theFirm = new TreeNode("theFirmId" , "The Firm" , "thriller");
ITreeNode lordOfTheRings= new TreeNode("lordOfTheRingsId" , "Lord of The Rings", "fantasy");
ITreeNode dumbNDumber = new TreeNode("dumbNDumberId" , "Dumb'n Dumber" , "comedy");
ITreeNode lionKing = new TreeNode("lionKingId" , "Lion King" , "cartoon");
ITreeNode snowWhite = new TreeNode("snowWhiteId" , "Snow White" , "cartoon");
movies.addChild(thrillers);
movies.addChild(fantasy);
movies.addChild(comedy);
movies.addChild(cartoons);
thrillers.addChild(thrillersNew);
thrillers.addChild(thrillersOld);
thrillersNew.addChild(theFirm);
thrillersOld.addChild(basicInstinct);
fantasy .addChild(lordOfTheRings);
cartoons .addChild(lionKing);
cartoons .addChild(snowWhite);
//comedy .addChild(dumbNDumber);
comedy .addChild(comedySub);
comedySub.addChild(comedySubSub);
tree.setRoot(movies);
tree.expand(movies.getId());
tree.expand(cartoons.getId());
tree.select(fantasy.getId());
tree.setSingleSelectionMode(false);
//storing the tree model instance in the session.
//this is where the tags get the tree model from later.
session.setAttribute("example", tree);
// request.setAttribute("example", tree);
}
%>
<html>
<head>
<title>Tree Tag - Single Page - (C) 2004 Jenkov Development</title>
<link rel="stylesheet" href="/prizetagsdemo/stylesheet.css" type="text/css">
</head>
<body>
<table cellspacing="0" cellpadding="5" style="border: 1 solid black;">
<tr><td>
<%-- Generating the Tree HTML --%>
<table cellspacing="0" cellpadding="0" border="0">
<tree:tree tree="example" node="example.node" includeRootNode="false" >
<tr><td
><table cellspacing="0" cellpadding="0" border="0">
<tr><td><tree:nodeIndent node="example.node" indentationType="type"><tree:nodeIndentVerticalLine indentationType="type" ><img src="../images/verticalLine.gif"></tree:nodeIndentVerticalLine><tree:nodeIndentBlankSpace indentationType="type" ><img src="../images/blankSpace.gif"></tree:nodeIndentBlankSpace></tree:nodeIndent></td>
<tree:nodeMatch node="example.node" expanded="false" hasChildren="true" isLastChild="false"><td><a href="<request:requestUri/>?expand=<tree:nodeId node="example.node"/>"><img src="../images/collapsedMidNode.gif" border="0"></a><img src="../images/closedFolder.gif"></td></tree:nodeMatch>
<tree:nodeMatch node="example.node" expanded="true" hasChildren="true" isLastChild="false"><td><a href="<request:requestUri/>?collapse=<tree:nodeId node="example.node"/>"><img src="../images/expandedMidNode.gif" border="0"></a><img src="../images/openFolder.gif"></td></tree:nodeMatch>
<tree:nodeMatch node="example.node" expanded="false" hasChildren="true" isLastChild="true" ><td><a href="<request:requestUri/>?expand=<tree:nodeId node="example.node"/>"><img src="../images/collapsedLastNode.gif" border="0"></a><img src="../images/closedFolder.gif"></td></tree:nodeMatch>
<tree:nodeMatch node="example.node" expanded="true" hasChildren="true" isLastChild="true" ><td><a href="<request:requestUri/>?collapse=<tree:nodeId node="example.node"/>"><img src="../images/expandedLastNode.gif" border="0"></a><img src="../images/openFolder.gif"></td></tree:nodeMatch>
<tree:nodeMatch node="example.node" expanded="false" hasChildren="false" isLastChild="false"><td><img src="../images/noChildrenMidNode.gif"><img src="../images/nonFolder.gif"></td></tree:nodeMatch>
<tree:nodeMatch node="example.node" expanded="false" hasChildren="false" isLastChild="true" ><td><img src="../images/noChildrenLastNode.gif"><img src="../images/nonFolder.gif"></td></tree:nodeMatch>
<td valign="top">
<tree:nodeMatch node="example.node" selected="true"><a href="<request:requestUri/>?unSelect=<tree:nodeId node="example.node"/>"><span style="Font-Size: 12px; Color: #CC0000"><tree:nodeName node="example.node"/></span></a></tree:nodeMatch>
<tree:nodeMatch node="example.node" selected="false"><a href="<request:requestUri/>?select=<tree:nodeId node="example.node"/>"><span style="Font-Size: 12px;"><tree:nodeName node="example.node"/></span></a></tree:nodeMatch>
</td>
</tr>
</table></td></tr>
</tree:tree>
</table>
</td>
<td valign="top" style="border-left: 1 solid black;">
Selected Node Detail:<br/><br/>
<%
ITree tree = (ITree) session.getAttribute("example");
ITreeNode node = new TreeNode(); //empty node, displayed when the tree isn't initialized yet.
if(tree != null && request.getParameter("select") != null){
node = tree.findNode(request.getParameter("select"));
}
%>
<table cellspacing="0" cellpadding="5">
<tr><td>Id </td><td><%=node.getId()%></td></tr>
<tr><td>Name</td><td><%=node.getName()%></td></tr>
<tr><td>Type</td><td><%=node.getType()%></td></tr>
</table>
</td>
</tr>
</table>
<br/>
<a href="<request:requestUri/>?collapse=all">Collapse All</a><br/>
<a href="<request:requestUri/>?expand=all">Expand All</a>
<br/><br/>
Type nodeId of node to exand, collapse etc. You can see the nodeId of a node by
clicking the node and reading the nodeId to the right of the tree.
<br/>
<form action="<request:requestUri/>">
<input type="text" name="expandAncestors">
<input type="submit" value="expand ancestors" >
</form>
<form action="<request:requestUri/>">
<input type="text" name="expandAncestorsAndSelf">
<input type="submit" value="expand ancestors and self" >
</form>
<form action="<request:requestUri/>">
<input type="text" name="expandDescendants">
<input type="submit" value="expand descendants" >
</form>
<form action="<request:requestUri/>">
<input type="text" name="expandDescendantsAndSelf">
<input type="submit" value="expand descendants and self" >
</form>
<form action="<request:requestUri/>">
<input type="text" name="expandParent">
<input type="submit" value="expand parent" >
</form>
<form action="<request:requestUri/>">
<input type="text" name="expandParentAndSelf">
<input type="submit" value="expand parent and self" >
</form>
There exists corresponding collapse, select and unSelect methods and parameters that can be used to
trigger the corresponding actions. Just play around with the links in the address bar and see.
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?