[Ajax]Java实现人员从两个Jsp中正向选择,反向选择功能

2016-12-23 07:51:04来源:CSDN作者:wbj_315人点击

第七城市

JSP 代码:

(1)groupUserSetting.jsp--:人员配置页面

<%@ page contentType="text/html;charset=UTF-8"%><%@ include file="/resource/common/js/header.jsp"%><%	String webapp = request.getContextPath();	String groupid = (String)request.getAttribute("groupId");%><html><head><base target='_self'><script type="text/javascript">//选择function sel(){	//调用可选择用户iframe页面上的js方法	var addUsers = complete.getAllCheckedUserIds();	if(addUsers=="")	{	    alert("请选择人员!");	}	else	{	  addUsers = ","+addUsers;	  if(confirm("是否确认?"))	  {	  		var url = "<%=webapp %>/a1d200101/saveUserSetting.act?flag=1&groupid=<%=groupid%>&userids="+addUsers;			ajaxRequest(url,"freshIframes","showFailure");	  }	}}//反选function unsel(){	//调用可选择用户iframe页面上的js方法	var deleteUsers = inside.getAllCheckedUserIds();	if(deleteUsers=="")	{	    alert("请选择人员!");	}	else	  {	  	  deleteUsers = ","+deleteUsers;		  if(confirm("是否确认?"))		  {	  		var url = "<%=webapp %>/a1d200101/saveUserSetting.act?flag=2&groupid=<%=groupid%>&userids="+deleteUsers;			ajaxRequest(url,"freshIframes","showFailure");					  }	  }}//保存之后的回调方法function freshIframes(originalRequest){	//调用iframe页面上的查询js方法	complete.doQuery();	inside.doQuery();}				function showFailure(originalRequest){    alert("保存异常");}</script><title>人员配置</title></head><body class="mainContent" ><jbfs:title title="人员树" isShowTime="false" isShowJspName="false"/><div id="mainContent"  style="margin:0px;"><form  method="post"  action="/a1d200101/userSetting.act"  ><div class="mainDiv" style="margin:0px;"><div  id="searchDiv3"><table border="0" cellpadding="0" cellspacing="0" class="simpleFormTable" width="100%" >  <tr id="queryUserZone"> 		<td valign="top" height="515" width="48%" align="left">			<iframe id="complete" align="left" frameborder="0" height="100%" scrolling="no" width="100%"			name="complete" marginheight="0" marginwidth="0"			src="<%=webapp %>/xtbg/a1d20/unAuthedUserList.jsp?neq_groupid=<%=request.getParameter("crs400") %>"></iframe>		</td>		<td width="4%" align="center">			<!-- 确定方法 -->		<input type="button" name="leftSel" id="leftSel" class="MyButton"			value=">" onClick="javascript:sel()" /> <br/>		<br />			<!-- 确定方法 -->		<input type="button" name="rightSel" id="rightSel" value="<" class="MyButton"			onclick="javascript:unsel();" />		</td>		<td valign="top" height="515" >			<iframe id="inside" align="right" frameborder="0" height="100%" scrolling="no" width="100%"			name="inside"			src="<%=webapp %>/xtbg/a1d20/authedUserList.jsp?eq_groupid=<%=request.getParameter("crs400") %>"></iframe>		</td></tr></table></div></div></form></div></body></html>

(2)authedUserList.jsp--已授权用户页面

<%@page import="java.util.LinkedHashMap"%><%@ page contentType="text/html;charset=UTF-8" %><%@ include file="/resource/common/js/header.jsp"%><%@ include file="/resource/common/js/sigma.jsp"%><%	String webapp = request.getContextPath();	String groupid = request.getParameter("eq_groupid");	pageContext.setAttribute("groupid", groupid);%><html><head><base target='_self'><script type="text/javascript">//查询列表function doQuery(){	SigmaUtil.doQuery(document.forms[0]);}   //获取所有选中的用户idfunction getAllCheckedUserIds(){	return SigmaUtil.getAllCheckedIds('userid');}</script><title>已授权的人员</title></head><body class="mainContent" style="margin:0px;padding:0px;"><div id="mainContent" style="margin:0px;padding:0px;"><jbfs:wrapArea id="areaId000" title="已授权用户" isDefaultWrap="false">	<form  method="post"  action="/a1d200101/selAuthedUser.act"  >		<table class="searchTable">		<tr class="odd">			<td class="searchHeader1" nowrap width="8%">编号</td>			<td class="searchHeader2" nowrap width="22%">				<jbfs:text property="like_usercode" size="18"/>			</td>			<td class="searchHeader1" nowrap width="8%">姓名</td>			<td class="searchHeader2" nowrap>				<jbfs:text property="like_username" size="18"/>			</td>		</tr>		<tr class="even">		<td colspan="4">		<table class="buttonTable">					<tr>		 				<td align="left" nowrap>													</td>						<td align="right" nowrap>							<jbfs:privilege url="" type="button" btnType="search" value="查询" onclick="javascript:showProgressBar('操作进行中,请稍候...');doQuery();"/>						</td>					</tr>				</table>		</td>		</tr>		</table>	</form>	<sgrid:table id="sigma" 	loadUrl="${pageContext.request.contextPath}/a1d200101/selAuthedUser.act?groupid=${groupid}"	 initJs="doQuery();" height="400px"		showIndexColumn="false" toolbarContent="nav | pagesize | reload | state" >		<sgrid:column width="10%" title="userid" id="userid" isCheckColumn="true" align="center"/>		<sgrid:column width="40%" title="编号" id="usercode"/>		<sgrid:column width="50%" title="姓名" id="username"/>	</sgrid:table></jbfs:wrapArea></body></html>
(3)unAuthedUserList.jsp--未授权用户页面

<%@ page contentType="text/html;charset=UTF-8" %><%@ include file="/resource/common/js/header.jsp"%><%@ include file="/resource/common/js/sigma.jsp"%><%	String webapp = request.getContextPath();	String groupid = request.getParameter("neq_groupid");	pageContext.setAttribute("groupid", groupid);%><html><head><base target='_self'><script type="text/javascript">//查询列表function doQuery(){	SigmaUtil.doQuery(document.forms[0]);}   //获取所有选中的用户idfunction getAllCheckedUserIds(){	return SigmaUtil.getAllCheckedIds('userid');}</script><title>未授权人员</title></head><body class="mainContent" style="margin:0px;padding:0px;"><div id="mainContent" style="margin:0px;padding:0px;"><jbfs:wrapArea id="areaId000" title="可授权用户" isDefaultWrap="false">	<form  method="post"  action="/a1d200101/selUnAuthedUser.act"  >		<table class="searchTable">		<tr class="odd">			<td class="searchHeader1" nowrap width="8%">编号</td>			<td class="searchHeader2" nowrap width="22%">				<jbfs:text property="like_usercode" size="18"/>			</td>			<td class="searchHeader1" nowrap width="8%">姓名</td>			<td class="searchHeader2" nowrap>				<jbfs:text property="like_username" size="18"/>			</td>		</tr>		<tr class="even">		<td colspan="4">		<table class="buttonTable">					<tr>		 				<td align="left" nowrap>													</td>						<td align="right" nowrap>							<jbfs:privilege url="" type="button" btnType="search" value="查询" onclick="javascript:showProgressBar('操作进行中,请稍候...');doQuery();"/>						</td>					</tr>				</table>		</td>		</tr>		</table>	<form>	<sgrid:table id="sigma" 	loadUrl="${pageContext.request.contextPath}/a1d200101/selUnAuthedUser.act?groupid=${groupid}"	 initJs="doQuery();" height="400px" 		showIndexColumn="false" toolbarContent="nav | pagesize | reload | state" >		<sgrid:column width="10%" title="userid" id="userid" isCheckColumn="true" align="center"/>		<sgrid:column width="40%" title="编号" id="usercode"/>		<sgrid:column width="50%" title="姓名" id="username"/>			</sgrid:table></jbfs:wrapArea></body></html>

Java代码:

A1D200101Controller.java

/**	 * 保存人员树分组配置	 * 	 * @param request	 * @param groupid,flag,userids	 * @return	 * @throws Exception	 */	@RequestMapping(value = "/saveUserSetting")	@ResponseBody	public String saveUserSetting(HttpServletRequest request, String flag, String groupid, String userids) throws Exception	{		if (flag.equals("1")) // 选择用户		{			String ownerid = SessionUtil.getUserId(request);			a1d200101Service.addUserSetting(groupid, userids,ownerid);		}		else		// 反选用户		{			a1d200101Service.deleteUserSetting(groupid, userids);		}		return "";	}
A1D200101Dao.java

	public void addSelectedUsers(String groupid, String userids, String ownerid) {		userids = userids.substring(1);		userids = userids.replaceAll(",", "','");		String sql = "insert into RS42(userid,groupid,ownerid) select userid,'" + groupid + "','"+ownerid+"' from sys_user where userid in ('" + userids + "')";		this.getjBaseDao().execute(sql);	}

ajaxRequest方法:

/**	 * 判断HttpServletRequest请求是否为Ajax请求	 *	 * @param request	 * @return boolean	 */	public static boolean isAjaxRequest(HttpServletRequest request)	{		boolean isAjaxRequest = false;		String reaHeader = request.getHeader("__REQUEST_TYPE");		if (reaHeader != null)		{			if (reaHeader.trim().equalsIgnoreCase("AJAX_REQUEST"))			{				isAjaxRequest = true;			}		}		return isAjaxRequest;	}

注:SigmaUtil.doQuery与SigmaUtil.getAllCheckedIds方法详见 代码片  sigmaUtil.js文件


第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台