struts2.3.1.2中使用标签生成动态树形结构的问题

nypdmax 2012-04-18 10:16:16
开发环境是eclipse indigo + struts 2.3.1.2 + tomcat 7.0.26,我参照一本书上的例子想用<sx:tree>标签(strus2.3里没有<s:tree>了)做动态树形目录,但是最后页面不显示这个树形结构,控制台没有错误信息,网页上debug也没有看到错误。但我把这些内容静态地用tree和treenode写在页面里就正常。求高人解答到底动态树形目录哪里有错,分不多了,最后的都拿出来了。
jsp页面如下:peerlist.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sx:head debug="true" cache="false" compressed="false" />
</head>
<body>
<h2>peer list</h2>
<div>
<sx:tree id="tree" rootNode="rootNode" nodeIdProperty= "nodeId" nodeTitleProperty="nodeName" childCollectionProperty="children" showRootGrid="true" showGrid="true">
</sx:tree>
</div>
<s:debug></s:debug>
</body>
<script type="text/javascript">
function treeNodeSelection(arg){
alert(arg.source.title+'selected');
}
dojo.addOnLoad(function(){
var t = dojo.widget.byId('tree');
var s = t.selector;
dojo.event.connect(s,'select','treeNodeSelection');
});
</script>
</html>

PeerTree.java:
package action;

import com.opensymphony.xwork2.ActionSupport;


public class PeerTree extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 4636831849868832412L;

//private int nodeId;
//private int nodeName;
//private TreeNodes[] childre;
private TreeNode rootNode;

public TreeNode getRootNode(){
return rootNode;
}

public void setRootNode(TreeNode rootNode){
this.rootNode = rootNode;
}

public String execute() throws Exception{
TreeNodes[] ca=new TreeNodes[1];
TreeNodes c1 = new TreeNodes();
c1.setId(11);
c1.setName("c1");
ca[0] = c1;

TreeNodes[] c = new TreeNodes[1];
TreeNodes child;
child = new TreeNodes();
child.setNodes(ca);
child.setId(1);
child.setName("test");
c[0]=child;

TreeNodes parent = new TreeNodes();
parent.setName("peer list");
parent.setId(0);
parent.setNodes(c);

rootNode = new TreeNode(parent);
return SUCCESS;
}
}
TreeNode.java:
package action;

public class TreeNode {
TreeNodes children;

public TreeNode(TreeNodes childrens){
children = childrens;
}

public int getId(){
return children.getId();
}
public void setId(int id){
children.setId(id);
}
public String getName(){
return children.getName();
}
public void setName(String name){
children.setName(name);
}
public TreeNode[] getChildren(){
if(children.getNodes() != null && children.getNodes().length >0){
int length = children.getNodes().length;
TreeNode[] treeNodes = new TreeNode[length];

for(int i=0;i<length;i++){
treeNodes[i]=new TreeNode(children.getNodes()[i]);
}
return treeNodes;
}
return new TreeNode[0];
}
}
TreeNodes.java:
package action;

import java.util.Arrays;

public class TreeNodes {
private int id;
private String name;
private TreeNodes[] nodes;

public int getId(){
return id;
}
public void setId(int nodeId){
this.id = nodeId;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public TreeNodes[] getNodes(){
return nodes;
}

public void setNodes(TreeNodes[] nodes){
this.nodes = new TreeNodes[0];
this.nodes = Arrays.copyOf(nodes, nodes.length);
}

}
struts.xml配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
-->
<package name="action" extends="struts-default" namespace="">
<action name="login" class="action.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="showPeerList" class="action.PeerTree">
<result name="success">/peerlist.jsp</result>
</action>
</package>


<!-- Add packages here -->

</struts>
...全文
289 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nypdmax 2012-04-19
没人知道吗?
回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2012-04-18 10:16
社区公告
暂无公告