Struts2中optiontransferselect 使用
来源:互联网 发布:电脑看本子软件 编辑:程序博客网 时间:2024/05/24 06:35
Action中:
public class DefineUserIdentAttrsAction extends ActionSupport {
/**
* 用户身份属性配置左边多选框.
*/
private String[] lEvent;
/**
* 用户身份属性配置右边多选框.
*/
private String[] rEvent;
/**
* 用户身份配置.
*/
private ISetUserIdentityAttrsService iSetUserIdentityAttrsService;
/**
* 获取自定义属性信息.
*/
private IConfigDUAttrsService iConfigDUAttrsService;
@Override
public String execute() {
// 初始化对象
SetUserIdentityAttrs transientInstance = null;
try {
transientInstance =
iSetUserIdentityAttrsService.findByDN(
DNTools.getRootDN(
Const.MODULECONFIG_SYNCHACCOUNT));
} catch (Exception ex) {
ex.printStackTrace();
ServletActionContext.getRequest().
setAttribute(SynchAccountConst.REQUEST_ATTR_MSG,
"访问LDAP失败,请联系系统管理员");
ServletActionContext.getRequest().
setAttribute(SynchAccountConst.REQUEST_ATTR_URL,
"../synchaccount/synchConfigAction.do");
return SynchAccountConst.JUMP_MSG;
}
String[] attrs = null;
if (transientInstance != null) {
String personAttrs = transientInstance.getPersonAttr();
if (personAttrs != null && !"".equals(personAttrs)) {
attrs = personAttrs.split(";");
}
}
Map leftMap = new Hashtable();
Map rightMap = new Hashtable();
// 获取用户属性
PersonSchemaDao personSchemaDao = PersonSchemaDao.getInstance();
SchemaVO schemavo = personSchemaDao.getSchemaVO();
List sortList = schemavo.getSortIndex();
Hashtable fieldNodes = schemavo.getFields();
schemavo = null;
Iterator iterator = sortList.iterator();
sortList = null;
while (iterator.hasNext()) {
String key = (String) iterator.next();
Field pom = (Field) fieldNodes.get(key);
if (pom == null || pom.isHidden()) {
continue;
}
boolean flag = false;
if (attrs != null) {
for (int i = 0; i < attrs.length; i++) {
if (key.equals(attrs[i])) {
flag = true;
break;
}
}
}
if (flag) {
rightMap.put(key, pom.getTitle());
} else {
leftMap.put(key, pom.getTitle());
}
}
iterator = null;
fieldNodes = null;
sortList = null;
// 自定义属性
List configList = null;
try {
configList = iConfigDUAttrsService.findAll();
if (configList != null) {
int userdefineListSize = configList.size();
for (int i = 0; i < userdefineListSize; i++) {
ConfigDefineUserAttrs configAttrs =
(ConfigDefineUserAttrs) configList.get(i);
boolean flag = false;
String key = configAttrs.getLdapAttrName();
if (attrs != null) {
for (int j = 0; j < attrs.length; j++) {
if (key.equals(attrs[j])) {
flag = true;
break;
}
}
}
if (flag) {
rightMap.put(key, configAttrs.getDisplayName());
} else {
leftMap.put(key, configAttrs.getDisplayName());
}
configAttrs = null;
}
configList = null;
}
} catch (Exception ex) {
ex.printStackTrace();
ServletActionContext.getRequest().
setAttribute(SynchAccountConst.REQUEST_ATTR_MSG,
"访问LDAP失败,请联系系统管理员");
ServletActionContext.getRequest().
setAttribute(SynchAccountConst.REQUEST_ATTR_URL,
"../synchaccount/defineUserIdentAttrsAction.do");
return SynchAccountConst.JUMP_MSG;
}
ServletActionContext.getRequest().setAttribute("leftEventMap",
leftMap);
ServletActionContext.getRequest().setAttribute("rightEventMap",
rightMap);
return Action.INPUT;
}
/**
* 保存用户身份属性配置.
*
* @return
* String
*
*/
public String save() {
if (valid()) { // 对页面输入进行检测
execute();
return INPUT;
}
SetUserIdentityAttrs transientInstance = new SetUserIdentityAttrs();
if (rEvent != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < rEvent.length; i++) {
sb.append(rEvent[i]);
sb.append(";");
}
transientInstance.setPersonAttr(sb.toString());
sb = null;
}
transientInstance.setDn(DNTools.getRootDN(
Const.MODULECONFIG_SYNCHACCOUNT));
try {
iSetUserIdentityAttrsService.save(transientInstance);
} catch (Exception ex) {
ex.printStackTrace();
ServletActionContext.getRequest().
setAttribute(SynchAccountConst.REQUEST_ATTR_MSG,
"访问LDAP失败,请联系系统管理员");
ServletActionContext.getRequest().
setAttribute(SynchAccountConst.REQUEST_ATTR_URL,
"../synchaccount/synchConfigAction.do");
return SynchAccountConst.JUMP_MSG;
}
return Action.SUCCESS;
}
/**
* 输入有效性检测.
*
* 注:在保存添加用户身份属性和保存修改用户身份属性中使用
*
* @return
* boolean
*/
private boolean valid() {
boolean flag = false;
if (rEvent == null) {
addFieldError("rEvent", "请选择用户身份属性");
flag = true;
}
return flag;
}
public void setiSetUserIdentityAttrsService(
ISetUserIdentityAttrsService iSetUserIdentityAttrsService) {
this.iSetUserIdentityAttrsService = iSetUserIdentityAttrsService;
}
public void setiConfigDUAttrsService(
IConfigDUAttrsService configDUAttrsService) {
this.iConfigDUAttrsService = configDUAttrsService;
}
public String[] getLEvent() {
return lEvent;
}
public void setLEvent(String[] lEvent) {
this.lEvent =
lEvent;
}
public String[] getREvent() {
return rEvent;
}
public void setREvent(String[] rEvent) {
this.rEvent =
rEvent;
}
}
JSP文件:
<%@page contentType="text/html" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="../common/subtop.jsp" %>
<html>
<head>
<s:head theme="ajax"/>
<script language="javascript">
function dosubmit(){
form1.action = "../synchaccount/defineUserIdentAttrsAction!save.do";
form1.onsubmit();
form1.submit();
}
</script>
<title>
<s:text name="synchaccount.defineuseridentattrs.jsp.title"/>
</title>
<link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
<body topmargin="0" leftMargin="0" >
<s:form name="form1"
namespace="/synchaccount"
method="post"
action="/auth/setAdminAction.do">
<table cellspacing="0" cellpadding="0" border="0" align="center" width="90%">
<tr>
<td width="35">
<img src="../image/an19.gif" width="35" height="25" hspace="4">
</td>
<td align="left">
<strong>
<s:text name="synchaccount.defineuseridentattrs.jsp.title"/>
</strong>
</td>
<td align="right">
<img src="../image/save.gif" border=0 onClick="dosubmit()"
hspace="4" style="CURSOR: hand" alt="保存" />
</td>
</tr>
</table>
<table width="90%" height="77" border="0" align="center"
cellpadding="0" cellspacing="0" cellpadding="0">
<tr>
<td height="12" colspan="3" background="../image/di14.gif">
</td>
</tr>
<tr bgcolor="#F9F9F9" align="right">
<td align="center" bgcolor="#F9F9F9" colspan="3">
<table>
<tr>
<td>
<s:optiontransferselect
rightTitle="用户身份属性列表"
leftTitle="用户属性列表"
name="lEvent"
list="#request.leftEventMap"
addAllToLeftLabel="<<-"
addAllToRightLabel="->>"
addToRightLabel="-->"
addToLeftLabel="<--"
allowSelectAll="false"
emptyOption="false"
allowUpDownOnLeft="false"
allowUpDownOnRight="false"
cssStyle="WIDTH: 151px; HEIGHT: 150px"
multiple="true"
doubleName="rEvent"
doubleList="#request.rightEventMap"
doubleEmptyOption="false"
doubleMultiple="true"
doubleCssStyle="WIDTH: 151px; HEIGHT: 150px"
/>
</td>
<td >
<font color="red">(*)
<s:property value="fieldErrors['apprFlowVo.rEvent'][0]" />
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="12" colspan="3" background="../image/di14.gif">
</td>
</tr>
</table>
</s:form>
</body>
</html>
注意:
JSP文件中需添加<s:head theme="ajax"/>;
JSP文件中需把form中onsub的值设为true,比如form1.onsubmit();
- Struts2中optiontransferselect 使用
- struts2 s:optiontransferselect 标签的使用
- struts2 s:optiontransferselect 标签的使用
- struts2标签optiontransferselect
- [Struts2]"s:optiontransferselect" 标签BUG
- struts2——optiontransferselect标签!!!
- struts2使用可生成交互的两个列表框的optiontransferselect标签
- struts2 的optiontransferselect之js代码
- struts2 optiontransferselect标签的一些属性
- Struts2 标签 optiontransferselect 不能左右移动
- strut2 optiontransferselect 标签使用如何在action中获取list和doublelist里面的数据
- optiontransferselect标签,optgroup标签,token标签的使用
- s:optiontransferselect
- struts2之optiontransferselect标签(从jsp跑通到action)(详解)
- 解决Struts2中的s:optiontransferselect排序后的数据获取的问题
- 解决Struts2中的s:optiontransferselect排序后的数据获取的问题
- struts2中使用OGNL
- Struts2中使用JSON
- 《富爸爸财务自由之路》读后摘录之(一)
- 打包NET框架的N种方式大比较[收藏]
- 协议__NetBEUI
- SQL Server的链接服务器技术小结
- Python里的多线程
- Struts2中optiontransferselect 使用
- 分拆字符串求和
- Hacking Vim 中文翻译 -- 前言
- [50.0%] 纪念
- links for English
- 修改XP默认只能使用guest帐户进行网络访问的办法
- keepalived UserGuide[翻译]-未完
- iPod经验对Kindle的启示
- JS 中的一些微小地方引起的误差积累