treescrollback.jsp
来自「部门结构树」· JSP 代码 · 共 157 行
JSP
157 行
<%@ 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());
//storing the tree model instance in the session.
//this is where the tags get the tree model from later.
session.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 onload="<%if(request.getParameter("scrollX")!=null){%>scrollBack(<%=request.getParameter("scrollX")%>, <%=request.getParameter("scrollY")%>);<%}%>">
<script type="text/javascript">
function scrollPositionAsParameters(){
//the document.all is only present in IE, so it's a way to determine the browser type and DOM hieararchy available.
scrollX = (document.all)?document.body.scrollLeft:window.pageXOffset;
scrollY = (document.all)?document.body.scrollTop :window.pageYOffset;
return "scrollX=" + scrollX + "&scrollY=" + scrollY;
}
function scrollBack(x, y){
window.scrollTo(x,y);
}
</script>
<h2>Tree - Correct Scrollback Demo</h2>
To see the correct scrollback effect of this tree demo, make the window <br/>
smaller than the tree, then scroll down or right, expand/collapse/select a tree node. <br/>
You will see that the tree page submits, and scrolls correctly back to the <br/>
position you had scrolled the window into, before the submit.
<br/><br/><br/>
<table cellspacing="0" cellpadding="5" style="border: 1px 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="javascript:location.href='<request:requestUri/>?expand=<tree:nodeId node="example.node"/>&' + scrollPositionAsParameters();"><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="javascript:location.href='<request:requestUri/>?collapse=<tree:nodeId node="example.node"/>&' + scrollPositionAsParameters();"><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="javascript:location.href='<request:requestUri/>?expand=<tree:nodeId node="example.node"/>&' + scrollPositionAsParameters();"><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="javascript:location.href='<request:requestUri/>?collapse=<tree:nodeId node="example.node"/>&' + scrollPositionAsParameters();"><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"><span style="Font-Size: 12px;"><b><tree:nodeName node="example.node"/></b></span></tree:nodeMatch>--%>
<tree:nodeMatch node="example.node" ><a href="javascript:location.href='<request:requestUri/>?select=<tree:nodeId node="example.node"/>&' + scrollPositionAsParameters();"><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>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?