在数据库中
System.do?method=toMenuManager
/**
* 显示到菜单配置页面
*/
public ActionForward toMenuManager(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("agentList", this.getPrivilegeDAO()
.findByGroupType22(1));
request.setAttribute("managerList", this.getPrivilegeDAO()
.findByGroupType33(0));
return mapping.findForward("toMenuManager");
}
其中"agentList" 对应jsp页面中的
c:forEach var="group" items="${requestScope.agentList}" varStatus="status">
"managerList" 对应jsp页面中的
<c:forEach var="group" items="${requestScope.managerList}" varStatus="status">
this.getPrivilegeDAO() 这个
1.在action中 private PrivilegeDAO privilegeDAO; set/get 出来的
2.需要在
appilicationContext.xml
<bean name="/system"
class="com.et.struts.action.SystemAction" singleton="false">
<property name="privilegeDAO">
<ref bean="privilegeDAO" />
</property>
findByGroupType22(1)
方法
public List findByGroupType22(Integer privilegeType){//
String hql="from Privilege where PrivilegeType='1' order by PIndex";
return this.hibernateHelper.query(hql);
}
findByGroupType33(0)
方法
public List findByGroupType33(Integer privilegeType){//
String hql="from Privilege where PrivilegeType='0' order by PIndex";
return this.hibernateHelper.query(hql);
}
当类型更改的时候菜单配置列表会有相应的变化
这个是jsp页面
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>menuManager.jsp</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">
<link href="../css/admin.css" type="text/css" rel="stylesheet" />
<link href="../../css/body.css" type="text/css" rel="stylesheet" />
<link href="agent.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="menu.js"></script>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
</head>
<body bgcolor="#8CBAEB">
<div class="div_main" >
<table width="400px" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr >
<td class="div_title" >菜单配置</td>
</tr>
<tr >
<td class="div_body" bgcolor="F8FCFD">
<form id="main" action="../../../system.do" method="post">
<input type=hidden name=method id=method value="menuUpdate">
<table class="div_table" bgcolor="F8FCFD" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#E0E0E0" >
<tr>
<td width="17%" align="center" valign="top">类型:</td>
<td width="34%" align="left">
<select name="type" id="type" onclick="selChange(this.value)">
<option value="1" selected="selected">坐席</option>
<option value="0">管理</option>
</select>
</td>
</tr>
<table>
<tr>
<td width="17%" align="center" valign="top">菜单配置列表:</td>
<td width="34%" align="left">
<div id="agent1" align="center">
<select name="agent" size="15" multiple="multiple">
<c:forEach var="group" items="${requestScope.agentList}" varStatus="status">
<option value="${group.pid}">${group.privilegeName}</option>
</c:forEach>
</select>
<label>
<input type="button" name="button" value="上移" onclick="Moveup(agent)">
<input type="button" name="button" value="下移" onclick="Movedown(agent)">
</label>
</div>
<div id="manager1" style="display: none" align="center">
<select name="manager" size="15" multiple="multiple" >
<c:forEach var="group" items="${requestScope.managerList}" varStatus="status">
<option value="${group.pid}">${group.privilegeName}</option>
</c:forEach>
</select>
<label>
<input type="button" name="button" value="上移" onclick="Moveup(manager)">
</label>
<label>
<input type="button" name="button" value="下移" onclick="Movedown(manager)">
</label>
</div>
</td>
</tr>
</table>
<tr>
<td height="30" colspan="2" align="center"><input name="botton" type="button" class="button1" value="提 交" onclick="toUpdate()"/>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</body>
</html:html>
其中
//为了到action中
action="../../../system.do"
//为了支持JavaScript脚本
<script type="text/javascript" src="menu.js"></script>
//为了能够调用脚本中的menuUpdate方法 跳转到action中去
<input type=hidden name=method id=method value="menuUpdate">
//为了 在提交的时候有个默认被选中,否则提交的时候为空,出现问题
<option value="1" selected="selected">坐席</option>
onclick="toUpdate() 跳转到js文件中的toUpdate方法中
menu.js文件
/**
*按照类型能够取得出来下拉列表
*/
function toUpdate() {
var typeObj = document.getElementById("type");
//alert(typeObj.value);
//按照管理类型把所有的列表选项都给选中
if(typeObj.value=='0'){
var managerObj = document.getElementById("manager");
for (var i=0;i<managerObj.length;i++){
managerObj.options[i].selected=true;
}
}
//按照坐席类型把所有的列表选项都给选中
if(typeObj.value=='1'){
var agentObj = document.getElementById("agent");
for (var i=0;i<agentObj.length;i++){
agentObj.options[i].selected=true;
}
}
//提交到action方法中
var method = document.getElementById("method");
method.value = "menuUpdate";
var mainForm = document.getElementById("main");
mainForm.submit();
}
/**
* 更新数据库菜单
*/
public ActionForward menuUpdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String type = request.getParameter("type");
String groupName[] = null;
if ("0".equals(type)) {
groupName = request.getParameterValues("manager");
}
if ("1".equals(type)) {
groupName = request.getParameterValues("agent");
}
if (groupName != null && groupName.length > 0) {
this.getPrivilegeDAO().update(groupName);
}
return mapping.findForward("ok");
}