处理树最主要是如何获得树的子节点,我通过ajax调用action的方式获得了树的下级节点,返回json字符串.
以下是获得部门树的部分代码
ext js 创建树
var Tree = Ext.tree;
deptTree = new Tree.TreePanel({
el : elementId,
autoScroll:true,
animate:true,
enableDD:true,
containerScroll: true,
loader: new Tree.TreeLoader({
dataUrl: CONTEXT_PATH + "/depts/deptTree.do",
baseParams: filter
})
});
// set the root node
root = new Tree.AsyncTreeNode({
text: rootDesc,
draggable:false,
id:'-1'
});
deptTree.setRootNode(root);
// render the deptTree
deptTree.render();
root.expand();
ext js 重新加载树
/**
* 重新加载树
*
* @param {f}
* f 过滤树的条件 如:{placeid:'xxxxx'}
*/
reload : function (f){
filter = f;
var loader = deptTree.getLoader();
deptTree.on('beforeload', function(){
loader.dataUrl = loader.dataUrl ;
loader.baseParams = filter;
});
root.reload();
}
XWork.xml
<action name="deptTree" method="getSubNodes"
class="cn.org.coral.biz.depts.view.deptExtAction">
</action>
Action(Webwork)
/**
* ExtTree获得下级节点数据
* @return
*/
public String getSubNodes() throws Exception {
this.getHttpServletResponse().setCharacterEncoding("UTF-8");
PrintWriter out = this.getHttpServletResponse().getWriter();
String jsonString = service.getSubNodes(getFilter());
out.print(jsonString);
return null;
}
Service(通过Spring管理)
/**
* ExtTree获得下级节点数据
* @param filter
* @return
*/
public String getSubNodes(Map filter) {
JSONArray josnArray = new JSONArray();
List<ExtTreeNode> nodes = manager.getSubNodes(filter);
if(nodes !=null && !nodes.isEmpty()){
josnArray = JSONArray.fromObject(nodes);
}
return josnArray == null ? "":josnArray.toString();
}
自定义ExtTreeNode 树节点对象
package cn.org.coral.core.ext.objects;
import java.io.Serializable;
import org.directwebremoting.annotations.DataTransferObject;
/**
* ExtTreeNode对象
* @author Lib
*
*/
@DataTransferObject
public class ExtTreeNode implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public ExtTreeNode(String id, String text, String cls, boolean leaf) {
super();
this.id = id;
this.text = text;
this.cls = cls;
this.leaf = leaf;
}
private String id;
private String text;
private String cls;
private boolean leaf;
/**
* @return the cls
*/
public String getCls() {
return cls;
}
/**
* @param cls the cls to set
*/
public void setCls(String cls) {
this.cls = cls;
}
/**
* 节点的id
* @return the id
*/
public String getId() {
return id;
}
/**
* 节点的id
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* 是否是叶子节点
* @return the leaf
*/
public boolean getLeaf() {
return leaf;
}
/**
* 是否是叶子节点
* @param leaf the leaf to set
*/
public void setLeaf(boolean leaf) {
this.leaf = leaf;
}
/**
* 节点显示名
* @return the text
*/
public String getText() {
return text;
}
/**
* 节点显示名
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}
}
分享到:
相关推荐
Spring + hibernate + webwork + freemarker 整合配置
相关的jar包截图 博文链接:https://zzwwyf.iteye.com/blog/162375
这是学习veloctiy+webwork+ibatis+spring所要的资料,对你入门学习很帮助!
针对监控服务器交换机等做的监控项目,主要运用当前流线的架构以及页面展示
HIBERNATE+WEBWORK+SPRING整合 可运行
webwork+spring+hibernate 开发资料,例子和配置方式,希望对您有帮助!
Hibernate+webwork+spring+oracle框架 导入Eclipse直接可以运行。运行请修改数据库连接,类库请自己下,附件不能上传过大内容
用webwork+hibernate+spring和mysql整合开发的小例子。
Webwork+spring+hibernate集成实例
些为webwork+spring+hibernate+freemarker (A)demo_project下的lib 包,需要配合使用..
struts2+webwork+spring.rarstruts2+webwork+spring.rar
如何实现webwork+spring+hibernate框架结合
最近在做个项目,用的是webwork+spring+hibernate,在网上看了不少webwork+spring的配制方式,大多都是老的配制方式,比如2.1.7的,webwork2.2.4新加了很多功能,和spring的配制也简单了很多,我做了一个简单的登录...
java私塾][Spring讲解+webwork2整合+webwork2整合全套,欢迎下载!
Spring+Webwork+iBatis 组合实例.txt
webwork2.2.7+spring+hibernate+oracle整合
webwork2.1.7+spring+hibernate+oracle整合
webwork+spring+hibernate整合开发网络书城 第5讲
个关于freemarker+webwork+spring+ibatis的demo文档