`
history1918
  • 浏览: 9965 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

DWR生成目录树

阅读更多
1、DWR配置文件   dwr.xml 位于WEB-INF目录下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"
"http://getahead.org/dwr//dwr30.dtd">
<dwr>
  <allow>
    <create creator="new" javascript="TreeFactory">
      <param name="class" value="com.hanz.dwr.TreeFactory"/>
    </create>
    <convert converter="bean" match="com.hanz.domain.Node"/>
    </allow>
</dwr>
2、目录管理器类
package com.hanz.dwr;

import java.util.List;

import com.hanz.domain.Node;

/**
* 根据用户身份产生不同树形菜单。
*
* @author 曹彦斌
*/
public class TreeFactory {
/**
* 根据树节点(非页节点)请求树叶节点列表。
*
* @param node_id
* @return
*/
public List<Node> getTree(String node_id) {
// ServletContext session = ServletActionContext.getServletContext();
// String status = (String) session.getAttribute("user_status");
// if ("1".equals(status)) {// 1、系统管理员
return getSysManagerTree(node_id);
// } else if ("2".equals(status)) {// 2、经理
// return getManagerTree(node_id);
// } else if ("3".equals(status)) {// 3、主管
// return getDirector(node_id);
// } else if ("4".equals(status)) {// 4、员工
// return getPersonnel(node_id);
// } else {
// return null;
// }
}

// 1系统管理员登录显示列表
private List<Node> getSysManagerTree(String node_id) {
java.util.List<Node> nodeList = new java.util.ArrayList<Node>();
if ("root".equals(node_id)) {
Node node = new Node(node_id + 1, "部门计划", false, null,
"images/1.gif");
nodeList.add(node);

Node node2 = new Node(node_id + 2, "个人办公", false, null,
"images/2.gif");
nodeList.add(node2);

Node node3 = new Node(node_id + 3, "系统配置", false, null,
"images/config.gif");
nodeList.add(node3);
Node node4 = new Node(node_id + 4, "财务管理", false, null,
"images/config.gif");
nodeList.add(node4);
Node node5 = new Node(node_id + 5, "工程管理", false, null,
"images/config.gif");
nodeList.add(node5);
Node node6 = new Node(node_id + 6, "申请管理", false, null,
"images/config.gif");
nodeList.add(node6);

} else if ("root1".equals(node_id)) {
Node node11 = new Node(node_id + 11, "部门计划处理", true,
"superAdminPages/project_1.jsp", "images/11.gif");
nodeList.add(node11);
} else if ("root2".equals(node_id)) {
// Node node21=new
// Node(node_id+21,"个人任务处理",true,"superAdminPages/task_1.jsp","images/21.gif");
// nodeList.add(node21);
Node node22 = new Node(node_id + 22, "个人资料编辑", true,
"superAdminPages/personalinfo_1.jsp", "images/22.gif");
nodeList.add(node22);
} else if ("root3".equals(node_id)) {
Node node31 = new Node(node_id + 31, "系统权限分配", true,
"superAdminPages/authority.jsp", "images/31.gif");
nodeList.add(node31);
Node node32 = new Node(node_id + 32, "系统部门管理", true,
"superAdminPages/departmentmanager.jsp", "images/31.gif");
nodeList.add(node32);
Node node33 = new Node(node_id + 33, "系统用户管理", true,
"superAdminPages/usermanager.jsp", "images/32.gif");
nodeList.add(node33);
} else if ("root4".equals(node_id)) {
Node node41 = new Node(node_id + 41, "资金池管理", true,
"superAdminPages/cashpool.jsp", "images/31.gif");
nodeList.add(node41);
Node node42 = new Node(node_id + 42, "资金审核管理", true,
"superAdminPages/cashcheck.jsp", "images/32.gif");
nodeList.add(node42);
}else if ("root5".equals(node_id)) {
Node node51 = new Node(node_id + 51, "项目管理", true,
"superAdminPages/project_1.jsp", "images/31.gif");
nodeList.add(node51);
Node node52 = new Node(node_id + 52, "产品管理", true,
"superAdminPages/product1.jsp", "images/32.gif");
nodeList.add(node52);
}
else if ("root6".equals(node_id)) {
Node node61 = new Node(node_id + 61, "申请资费管理", true,
"superAdminPages/project_1.jsp", "images/31.gif");
nodeList.add(node61);
Node node62 = new Node(node_id + 62, "项目报销管理", true,
"superAdminPages/product1.jsp", "images/32.gif");
nodeList.add(node62);
}
return nodeList;
}

// 2经理登录显示菜单列表
private List<Node> getManagerTree(String node_id) {
java.util.List<Node> nodeList = new java.util.ArrayList<Node>();
if ("root".equals(node_id)) {
Node node = new Node(node_id + 1, "部门计划", false, null,
"images/1.gif");
nodeList.add(node);

Node node2 = new Node(node_id + 2, "个人办公", false, null,
"images/2.gif");
nodeList.add(node2);

Node node3 = new Node(node_id + 3, "部门管理", false, null,
"images/3.gif");
nodeList.add(node3);
} else if ("root1".equals(node_id)) {
Node node11 = new Node(node_id + 11, "部门计划查看", true,
"managerPages/project_2.jsp", "images/11.gif");
nodeList.add(node11);
} else if ("root2".equals(node_id)) {
// Node node21=new
// Node(node_id+21,"个人任务处理",true,"#","images/21.gif");
// nodeList.add(node21);
Node node22 = new Node(node_id + 22, "个人资料编辑", true,
"managerPages/personalinfo_2.jsp", "images/22.gif");
nodeList.add(node22);
} else if ("root3".equals(node_id)) {
Node node31 = new Node(node_id + 31, "人员查询", true,
"managerPages/staffsearch.jsp", "images/33.gif");
nodeList.add(node31);
}
return nodeList;
}

// 3主管登录显示菜单列表
private List<Node> getDirector(String node_id) {
java.util.List<Node> nodeList = new java.util.ArrayList<Node>();
if ("root".equals(node_id)) {
Node node = new Node(node_id + 1, "部门计划", false, null,
"images/1.gif");
nodeList.add(node);

Node node2 = new Node(node_id + 2, "个人办公", false, null,
"images/2.gif");
nodeList.add(node2);

Node node3 = new Node(node_id + 3, "部门管理", false, null,
"images/3.gif");
nodeList.add(node3);
} else if ("root1".equals(node_id)) {
Node node11 = new Node(node_id + 11, "部门计划处理", true,
"directorPages/project_3.jsp", "images/11.gif");
nodeList.add(node11);
} else if ("root2".equals(node_id)) {
Node node21 = new Node(node_id + 21, "个人任务处理", true,
"directorPages/taskdeal.jsp", "images/21.gif");
nodeList.add(node21);
Node node22 = new Node(node_id + 22, "个人资料编辑", true,
"directorPages/personalinfo_3.jsp", "images/22.gif");
nodeList.add(node22);
} else if ("root3".equals(node_id)) {
Node node31 = new Node(node_id + 31, "人员管理", true,
"directorPages/staffmanager.jsp", "images/33.gif");
nodeList.add(node31);
}
return nodeList;
}

// 4员工登录显示菜单列表
private List<Node> getPersonnel(String node_id) {
java.util.List<Node> nodeList = new java.util.ArrayList<Node>();
if ("root".equals(node_id)) {
Node node = new Node(node_id + 1, "个人办公", false, null,
"images/2.gif");
nodeList.add(node);
} else if ("root1".equals(node_id)) {
Node node11 = new Node(node_id + 11, "个人任务处理", true,
"staffPages/taskdeal.jsp", "images/21.gif");
nodeList.add(node11);
Node node12 = new Node(node_id + 22, "个人资料编辑", true,
"staffPages/personalinfo_4.jsp", "images/22.gif");
nodeList.add(node12);
}
return nodeList;
}
}
3、目录辅助类
package com.hanz.domain;
/**
* 树节点
* @author 曹彦斌
*/
public class Node {
private String id;
private String text;
private boolean leaf;
private String icon;
private String url;

public Node(String id,String text,boolean leaf,String url,String icon){
this.id = id;
this.text = text;
this.leaf = leaf;
this.url = url;
this.icon = icon;
}

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean isLeaf() {
return leaf;
}
public void setLeaf(boolean leaf) {
this.leaf = leaf;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
//JSON形式显示该对象
public String toString(){
return "{id:"+id+",text:"+text+",leaf:"+leaf+",url:"+url+"}";
}

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}
}
4、页面使用代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>汉众ERP管理系统</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css" media="all">     
    .allow-float {clear:none!important;} /* 允许该元素浮动 */    
    .stop-float {clear:both!important;} /* 阻止该元素浮动 */
.float-left {float:left;padding-left:20px}   /*浮动到左边*/
.float-right{float:right;padding-left:20px}
#loading {
position: absolute;
left: 40%;
top: 40%;
padding: 2px;
z-index: 20001;
height: auto;
color: #225588;
}

#loading .loading-indicator {
background: greenyellow;
color: #444;
font: bold 13px tahoma, arial, helvetica;
padding: 10px;
margin: 0;
height: auto;
}

#loading-msg {
font: normal 10px arial, tahoma, sans-serif;

.save {
   background-image:url(images/save.png) !important;
}
.reset{
background-image:url(images/reset.jpg) !important;
}
.rework{
background-image:url(images/rework.png) !important;
}
.search{
background-image:url(images/search.png) !important;
}
.add{
background-image:url(images/add.gif) !important;
}
.get{
    background-image:url(images/get.gif) !important;
}
.cancel{
background-image:url(images/cancel.png) !important;
}
.taskdispatcher{
background-image:url(images/ico_9.gif) !important;
}
.ok{
background-image:url(images/ok.png) !important;
}
.loading{
background-image:url(images/ico_9.gif) !important;
}
    </style>
  </head>
 
  <body>
   <div id="loading">
<div class="loading-indicator">
<img src="images/extanim33.gif" width="32" height="32"
style="margin-right: 8px; float: left; vertical-align: top;" />
    ERP管理系统
<br />
<span id="loading-msg"><font color="red">提示:</font>加载中,请耐心等待...</span>
</div>
</div>
<script type="text/javascript">document.getElementById('loading-msg').innerHTML = '<font color="red">提示:</font>加载中,请耐心等待...';</script>

    <!-- ExtJS样式 -->
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
<!-- 自定义样式 -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/ext-patch.css" />
<!-- ExtJS基本类库 -->
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"></script>
<script type="text/javascript" src="ext/source/locale/ext-lang-zh_CN.js"></script>
<!-- DWR引用类 -->
<script type='text/javascript' src='/hanz_erp/dwr/interface/Heartbeat.js'></script>
<script type='text/javascript' src='/hanz_erp/dwr/interface/TreeFactory.js'></script>
    <script type='text/javascript' src='/hanz_erp/dwr/engine.js'></script>
    <script type='text/javascript' src='/hanz_erp/dwr/util.js'></script>
<!-- 自定义js类 -->
<script type="text/javascript" src="js/DWRTreeLoader.js"></script>
<script type="text/javascript" src="js/themeChange.js"></script>
<script type="text/javascript" src="js/dwrproxy.js"></script>

<script type="text/javascript">
Ext.onReady(function(){
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
var root = new Ext.tree.AsyncTreeNode({
text : 'ERP理系统',
id:'root',
icon:'images/root.gif',
expanded : true//默认展开根节点
});

//异步请求数据
var loader = new Ext.ux.DWRTreeLoader({
//dwrMethod: TreeFactory.getTree//
dwrCall:TreeFactory.getTree//DWRTreeLoader2.1版使用
});

var menu = new Ext.tree.TreePanel({
loader:loader,//加载数据
border : false,
autoScroll:true,
useArrows: true,//使用vista箭头
enableDD: true,//允许拖曳操作
root : root,
hrefTarget : 'mainContent',
containerScroll: true,
listeners : {
click : function(node,e){
if(null!=node.attributes.url){
mainPanel.expand(true);//若不添加该功能,当收起右边面板后,再单击树叶节点会报错。
mainPanel.load({
url:node.attributes.url,
callback : function(){
mainPanel.setTitle(node.text);
},
nocache:true,//设置不缓存
scripts: true
});
}
}
}
,
tbar : [
'皮肤选择:',
{
xtype : 'themeChange',
width : 120,
listWidth : 120
},
'->'
]
});
new Ext.Viewport({
layout:'border',//表格布局
items: [{
collapsible: true,
contentEl:'top-logo',
region: 'north',//指定子面板所在区域为north
height: 70
},{
title : '功能菜单',
items : menu,
split:true,
collapsible: true,
region:'west',//指定子面板所在区域为west
width: 195
},{
title: '系统说明',
contentEl : 'aboutDiv',
collapsible: true,
autoScroll:true,
id : 'mainContent',
region:'center'//指定子面板所在区域为center
},
{
    region:"south",
    height:20,
    title : '<center></center>'
}]
});
var mainPanel = Ext.getCmp('mainContent');
//定时发送心跳信息,以保证会话不挂断。
HeartbeatMsg = function(){
Heartbeat.sendMsg("${user.name}",function(data){

});
}
//240000:4分钟后发送心跳
interval=setInterval(HeartbeatMsg,240000, "Interval called");
});
</script>

    <div id='top-logo'>
  <img src="images/hdr.jpg" height="70" width="100%"/>
</div>
<div id='aboutDiv' style='height:500;width:100%;text-align:center;line-height:300px'>
   <font color="blue" size="+1">欢迎登录ERP管理系统,本系统采用Spring3.0+Struts2.2+Hibernate3.6+ExtJS3.2.0+DWR框架!</font>
</div>
    <div id="submit_window"></div>
<script type="text/javascript">
   Ext.get('loading').remove();
   function showAbout(){
   Ext.Msg.alert("message","开发成员:曹彦斌");
   }
    </script>
  </body>
</html>
  • dwr.jar (1.1 MB)
  • 下载次数: 24
  • src.zip (213.2 KB)
  • 下载次数: 17
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics