您好,登錄后才能下訂單哦!
1、listUI.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib uri="/struts-tags" prefix="s" %> <html> <head> <%@include file="/common/header.jsp"%> <title>角色管理</title> <script type="text/javascript"> //全選、全反選 function doSelectAll(){ // jquery 1.6 前 //$("input[name=selectedRow]").attr("checked", $("#selAll").is(":checked")); //prop jquery 1.6+建議使用 $("input[name=selectedRow]").prop("checked", $("#selAll").is(":checked")); } //新增角色 function doAdd(){ document.forms[0].action = "${basePath}/tax/role_addUI.action"; document.forms[0].submit(); } //編輯角色 function doEdit(id){ document.forms[0].action = "${basePath}/tax/role_editUI.action?role.roleId="+id; document.forms[0].submit(); } //刪除角色 function doDelete(id){ document.forms[0].action = "${basePath}/tax/role_delete.action?role.roleId="+id; document.forms[0].submit(); } //批量刪除 function doDeleteAll(){ document.forms[0].action = "${basePath}/tax/role_deleteSelected.action"; document.forms[0].submit(); } </script> </head> <body class="rightBody"> <form name="form1" action="" method="post"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>角色管理 </strong></div> </div> <div class="search_art"> <li> 角色名稱:<s:textfield name="role.name" cssClass="s_text" id="roleName" cssStyle="width:160px;"/> </li> <li><input type="button" class="s_button" value="搜 索" onclick="doSearch()"/></li> <li > <input type="button" value="新增" class="s_button" onclick="doAdd()"/> <input type="button" value="刪除" class="s_button" onclick="doDeleteAll()"/> </li> </div> <div class="t_list" > <table width="100%" border="0"> <tr class="t_tit"> <td width="30" align="center"><input type="checkbox" id="selAll" onclick="doSelectAll()" /></td> <td width="120" align="center">角色名稱</td> <td align="center">權(quán)限</td> <td width="80" align="center">狀態(tài)</td> <td width="120" align="center">操作</td> </tr> <s:iterator value="roleList" status="vs"> <tr <s:if test="#vs.odd">bgcolor="f8f8f8"</s:if> > <td align="center"><input type="checkbox" name="selectedRow" value="<s:property value="roleId"/>"/></td> <td align="center"><s:property value="name"/></td> <td align="center"> <s:iterator value="rolePrivileges"> <s:property value="#privilegeMap[id.code]"/> </s:iterator> </td> <td align="center"> <s:if test="state == 1">有效</s:if><s:else>無效</s:else> </td> <td align="center"> <a href="javascript:doEdit('<s:property value="roleId"/>')">編輯</a> <a href="javascript:doDelete('<s:property value="roleId"/>')">刪除</a> </td> </tr> </s:iterator> </table> </div> </div> <div class="c_pate" > <table width="100%" class="pageDown" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right"> 總共1條記錄,當(dāng)前第 1 頁,共 1 頁 <a href="#">上一頁</a> <a href="#">下一頁</a> 到 <input type="text" onkeypress="if(event.keyCode == 13){doGoPage(this.value);}" min="1" max="" value="1" /> </td> </tr> </table> </div> </div> </div> </form> </body> </html>
知識(shí)點(diǎn)(1):從map當(dāng)中取數(shù)據(jù)
后臺(tái)代碼
//列表頁面 public String listUI(){ //加載權(quán)限集合 ActionContext.getContext().getContextMap().put("privilegeMap", PrivilegeStatics.PRIVILEGE_MAP); roleList = roleService.findAll(); return "listUI"; }
在JSP頁面取出privilegeMap對象中的數(shù)據(jù)
<s:iterator value="roleList" status="vs"> <s:iterator value="rolePrivileges"> <s:property value="#privilegeMap[id.code]"/> </s:iterator> </s:iterator>
知識(shí)點(diǎn)(2):
在定義的時(shí)候,雖然是String類型,但是在JSP頁面判斷的時(shí)候,似乎沒有區(qū)分
private String state;
<s:if test="state == 1">有效</s:if><s:else>無效</s:else>
2、addUI.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <%@include file="/common/header.jsp"%> <title>角色管理</title> </head> <body class="rightBody"> <form id="form" name="form" action="${basePath}/tax/role_add.action" method="post" enctype="multipart/form-data"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>角色管理</strong> - 新增角色</div></div> <div class="tableH2">新增角色</div> <table id="baseInfo" width="100%" align="center" class="list" border="0" cellpadding="0" cellspacing="0" > <tr> <td class="tdBg" width="200px">角色名稱:</td> <td><s:textfield name="role.name" /></td> </tr> <tr> <td class="tdBg" width="200px">角色權(quán)限:</td> <td> <!-- This is just a detail of the Java Map API. Instead, it iterates over Entry objects. The Entry object has two properties, the key and the value. By default, the select component’s listKey attribute will be set to key. Also by default, the listValue attribute will be set to value. If you’re using Maps, you can sometimes accept these defaults. 因此,如果listKey="key"并且listValue="value",那么這兩個(gè)值可以省略。 另外,如果省略name屬性,會(huì)報(bào)錯(cuò)! --> <s:checkboxlist list="#privilegeMap" name="privilegeIds" listKey="key" listValue="value"></s:checkboxlist> </td> </tr> <tr> <td class="tdBg" width="200px">狀態(tài):</td> <td><s:radio list="#{'1':'有效','0':'無效'}" name="role.state" value="1"/></td> </tr> </table> <div class="tc mt20"> <input type="submit" class="btnB2" value="保存" /> <input type="button" onclick="javascript:history.go(-1)" class="btnB2" value="返回" /> </div> </div></div></div> </form> </body> </html>
知識(shí)點(diǎn)(1):checklistbox
<!-- This is just a detail of the Java Map API. Instead, it iterates over Entry objects. The Entry object has two properties, the key and the value. By default, the select component’s listKey attribute will be set to key. Also by default, the listValue attribute will be set to value. If you’re using Maps, you can sometimes accept these defaults. 因此,如果listKey="key"并且listValue="value",那么這兩個(gè)值可以省略。 另外,如果省略name屬性,會(huì)報(bào)錯(cuò)! --> <s:checkboxlist list="#privilegeMap" name="privilegeIds" listKey="key" listValue="value"></s:checkboxlist>
知識(shí)點(diǎn)(2):radio 有默認(rèn)值
<s:radio list="#{'1':'有效','0':'無效'}" name="role.state" value="1"/>
3、editUI.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <%@include file="/common/header.jsp"%> <title>角色管理</title> </head> <body class="rightBody"> <form id="form" name="form" action="${basePath}/tax/role_edit.action" method="post" enctype="multipart/form-data"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>角色管理</strong> - 編輯角色</div></div> <div class="tableH2">編輯角色</div> <table id="baseInfo" width="100%" align="center" class="list" border="0" cellpadding="0" cellspacing="0" > <tr> <td class="tdBg" width="200px">角色名稱:</td> <td><s:textfield name="role.name" /></td> </tr> <tr> <td class="tdBg" width="200px">角色權(quán)限:</td> <td> <s:checkboxlist list="privilegeMap" name="privilegeIds"></s:checkboxlist> </td> </tr> <tr> <td class="tdBg" width="200px">狀態(tài):</td> <td><s:radio list="#{'1':'有效','0':'無效'}" name="role.state"/></td> </tr> </table> <s:hidden name="role.roleId"/> <div class="tc mt20"> <input type="submit" class="btnB2" value="保存" /> <input type="button" onclick="javascript:history.go(-1)" class="btnB2" value="返回" /> </div> </div></div></div> </form> </body> </html>
知識(shí)點(diǎn)(1):radio 在編輯頁面,不需要設(shè)置默認(rèn)值,而是使用它的實(shí)際值
<s:radio list="#{'1':'有效','0':'無效'}" name="role.state"/>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。