无意中看到了struts2的标签能做树形结构,于是便去做了一下,发现了问题还真不少,先让我归纳一下,问题主要如下:
第一、<s:tree>标签不是struts-tags里面的标签,而是struts-dojo-tags里面的标签,使用的人在声明标签的时候记得是使用<%@ taglib prefix="s" uri="/struts-dojo-tags"%>的方法。当然咯,要引入struts2-dojo-plugin-2.2.3.jar这个包。
第二、自从struts2.1.6之后,<s:head theme="ajax" debug="true">就要用
<sd:head theme="xhtml" /><s:head parseContent="true" />两句代替,原因好像是因为struts2 的高版本吧ajax如何到dojo那个包里面去了,具体是啥样本人也不清楚,因为个人一直觉得达到自己要求就不用再去深究了,要用到的再深究。上面的<sd:......>的sd是<%@ taglib prefix="sd" uri="/struts-tags"%>标签
第三、在子节点要想达到点击跳到另一个页面的效果,需要在label标签中加上<a href="">显示的名称</a>
<s:tree>本来就用的很少。为了方便大家,我把自己页面的代码贴出来,供大家参考:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="sx" uri="/struts-tags"%>
<%@ taglib prefix="s" uri="/struts-dojo-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Struts 2 AJAX - Tree</title>
<sx:head theme="xhtml" />
<s:head parseContent="true" />
</head>
<body>
<table width="100%" border="1">
<tr>
<td colspan="2" height="100px">
<center>
李仲声J2ee功能集
</center>
</td>
</tr>
<tr>
<td height="500px" width="200px">
<h2>
Tree
</h2>
<div style="float: left; margin-right: 50px;">
<s:tree label="parent" id="parentId"
templateCssPath="/struts/tree.css" showRootGrid="true"
showGrid="true">
<s:treenode label="child1" id="child1Id">
<s:treenode
label="<a href='../lzs/mainwork/autoComplete/JQueryAutoComplete.html' target='show'>google搜索提示功能</a>"
id="grandchild1Id" />
<s:treenode label="grandchild2" id="grandchild2Id" />
<s:treenode label="grandchild3" id="grandchild3Id" />
</s:treenode>
<s:treenode label="child2" id="child2Id" />
<s:treenode label="child3" id="child3Id" />
<s:treenode label="child4" id="child4Id" />
<s:treenode label="child5" id="child5Id">
<s:treenode label="gChild1" id="gChild1Id" />
<s:treenode label="gChild2" id="gChild2Id" />
</s:treenode>
</s:tree>
</div>
</td>
<td>
<iframe src="../wellcome.jsp" scrolling="auto" frameborder="0"
name="show" id="show"></iframe>
</td>
</tr>
</table>
</body>
</html>