关于级联菜单的动态生成以及状态回显

<%@page import="com.taiji.waf.daxing.wsgl.getvalue.GetSelectvalue"%><%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/wafplatform/include.jsp" %>
<%@ page import="com.taiji.waf.daxing.wsgl.*"%>
<%@ page import="java.util.*"%>
 <%
    //拿到后台动态生成的机构问题容器
    GetSelectvalue getSelectvalue = new GetSelectvalue();
    ArrayList list  = new ArrayList();
    if(getSelectvalue.getValue() != null && !(getSelectvalue.getValue()).equals("")) {
        list = (ArrayList)getSelectvalue.getValue();
    }
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Archives</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <link href="css/16B/style.css" rel="stylesheet" type="text/css"/>
  <style>.discolor tr:hover td{background:#FFF7C2;}
  .trcolor1{
    background:#edf7ff;
    text-shadow: 1px 1px 1px #fff;
    border:#779eba solid 1px;
    text-align:center;    
  }
  .trwhite1{
    background:#fff;
    text-shadow: 1px 1px 1px #fff;
    border:#779eba solid 1px;
    text-align:center;    
 }
 .button1{
    height:24px;
    /*filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#90baf2', 
endColorStr='#688bcc', gradientType='0');*/
    background: url(images/yjwz_fenlei-cardtit.png) repeat-x;
    border:none;
    font-size:14px;
    color:#2f4674;
    /*color:#603;*/
    text-align:center;
    padding:0 8px;
    -moz-border-radius: 6px; 
    -webkit-border-radius: 6px;
    border-radius: 6px;
    cursor:pointer;
}
.button1:hover{
    height:24px;
    /*filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#90baf2', 
endColorStr='#688bcc', gradientType='0');*/
    background:url(images/btn_blue.png) repeat-x;
    border:none;
    font-size:14px;
    color:#2f4674;
    /*color:#603;*/
    text-align:center;
    padding:0 8px;
    -moz-border-radius: 6px; 
    -webkit-border-radius: 6px;
    border-radius: 6px;
    cursor:pointer;
}
  </style>
  <meta http-equiv="Pragma" content="no-cache"/>
  <script src="js/common.js"></script>
  <script src="js/16B/showSearch.js"></script>
  <script language="javascript" type="text/javascript" src="js/calendar/WdatePicker.js"></script>
  <script>
  function deleteArchives(){
    if(hasSelect()){
       if(confirm ("是否真要删除?")){
          archivesForm.action="deleteArchives.action";
          archivesForm.submit();
        }
  }else{
      alert("您还没有选择要删除的选项");
  }
  }
  function editArchives(id){
    archivesForm.action="editArchives.action?archives.id="+id;
    archivesForm.submit();
  }
  function viewArchives(id){
    archivesForm.action="viewArchives.action?archives.id="+id;
    archivesForm.submit();
  }
  function newArchives(){
    archivesForm.action="newArchives.action";
    archivesForm.submit();
  }
  function search(){
    archivesForm.start.value="0";
     listArchives();
  }
  function listArchives(){
    archivesForm.action="listArchives.action";
    archivesForm.submit();
  }
  function turnPage(start){
    var length = archivesForm.length.value;
    archivesForm.reset();
    archivesForm.start.value=start;
    archivesForm.length.value=length;
    archivesForm.action="listArchives.action";
    archivesForm.submit();
  }
  function hasSelect(){
    var cbs = document.getElementsByName("ids");
     for(i=0;i<cbs.length;i++){
       if(cbs[i].checked==true)
         return true;
     }
     return false;
  }
  function selectAll(){
    var cbs = document.getElementsByName("ids");
     for(i=0;i<cbs.length;i++){
       cbs[i].checked=true;
     }
    selectBox.href="javascript:unSelectAll()";
    selectBox.innerText="不选";
  }
  function unSelectAll(){
    var cbs = document.getElementsByName("ids");
     for(i=0;i<cbs.length;i++){
       cbs[i].checked=false;
     }
    selectBox.href="javascript:selectAll()";
    selectBox.innerText="全选";
  }
  function isNumber(str){
    var digits = "0123456789";
    var i = 0;
    var sLength = str.length;
    while ((i < sLength)){
      var c = str.charAt(i);
      if (digits.indexOf(c) == -1) return false;
      i++;
    }
    return true;
  }
  function goPage(start){
    var page = archivesForm.page.value;
    var maxpage = <s:property value="listBean.maxPageCount"/>;
    if(!isNumber(page)){
      alert("页数请输入正整数!");
      archivesForm.page.focus();
      return;
    }
    var numpage = new Number(page);
    var nummaxpage = new Number(maxpage);
    if(numpage<=0){
      alert("页数应该大于等于1!");
      archivesForm.page.focus();
      return;
    }
    if(numpage > nummaxpage){
      alert("页数超出最大!");
      archivesForm.page.focus();
      return;
    }
    if(numpage==1){
      var start = 0;
    }else{
      var start = (numpage-1)*<s:property value="listBean.length"/>;
    }
    turnPage(start);
  }

  /*根据下拉菜单的选择进行动态数据加载*/
  function addItem() {
    //默认生成第一个下拉菜单的联动条件
    if(archivesForm.dept.selectedIndex == 0) {
        archivesForm.problem.length = 1;
        archivesForm.problem.selectedIndex = 0;
        archivesForm.problem.options[0].text="--请选择--";
        archivesForm.problem.options[0].value="";
    }  
    <%  //动态生成其余的下拉菜单联动条件
        for(int i = 0; i < list.size(); i++) {
            ArrayList arrayList = new ArrayList();
            arrayList = (ArrayList)list.get(i);
            int length = arrayList.size() - 1;
    %>
            if(archivesForm.dept.selectedIndex == <%= i+1%>) {
                archivesForm.problem.length = <%=length%>;
                archivesForm.problem.selectedIndex = 0;
        <%
            for(int j = 1; j < arrayList.size(); j++) {
                String str = (String)arrayList.get(j);
        %>
                archivesForm.problem.options[<%=j-1%>].text="<%=str%>";
                archivesForm.problem.options[<%=j-1%>].value="<%=str%>";
        <%    
            }
        %>
            }
    <%
        }
    %>
  }
  /*期限和排序的查询状态回滚 */
  function backSearch() {
    var qixian = document.getElementById("qxback").value;
    var length = document.getElementById("qixian").length;  
    for(var i = 0; i < length; i++) {
        if(document.getElementById("qixian").options[i].value == qixian) {
            document.getElementById("qixian").options[i].selected = "selected";
        }
    }
    var paixu = document.getElementById("pxback").value;
    var length2 = document.getElementById("paixu").length;
    for(var i = 0; i < length2; i++) {
        if(document.getElementById("paixu").options[i].value == paixu) {
            document.getElementById("paixu").options[i].selected = "selected";
        }
    }
  }
  /*机构问题态回滚 */
  function backdept() {
    var dept = document.getElementById("deptback").value;
    var length = document.getElementById("dept").length; 
    for(var i = 0; i < length; i++) {
        if(document.getElementById("dept").options[i].value == dept) {
            document.getElementById("dept").options[i].selected = "selected";
        }
    }
  }
  function backproblem() {
      var pro = document.getElementById("problemback").value;
      var length = document.getElementById("problem").length;
      for(var i = 0; i < length; i++) {
          if(document.getElementById("problem").options[i].value == pro) {
              document.getElementById("problem").options[i].selected = "selected";
          }
      }
  }
  </script>
</head>
<body bgcolor="white" onload="backSearch();backdept();addItem();backproblem()">
<form name="archivesForm" method="post" action="archives.action">
  <!--标题栏-->
  <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabtitle">
    <tr>
      <td class="titleFont2">档案文件目录</td>
      <td class="searchTltBar" onclick="showSearch(this,'searchTop')" title="展开查询">&nbsp;</td>
    </tr>
  </table>
  <!--查询区-->
  <div id="searchTop" class="searchDiv" style="display:none;">
  <table width="98%" border="0" cellpadding="3" cellspacing="0" align="center" class="tabout">
     <tr class="trcolor">
      <!-- 机构回显标识 -->
      <input type="text" id="deptback" value="<s:property value="dept"/>" class="inputTextNormal" style="display: none"/>
      <td class="tdFormText">机构:</td>
      <td class="tdFormInput">
      <select id="dept" name="dept" onChange="addItem()">
      <option selected="selected" value="">--请选择--</option>
      <%
          for(int i = 0; i < list.size(); i++) {
              ArrayList arrayList = new ArrayList();
            arrayList = (ArrayList)list.get(i);
      %>
          <option value="<%=arrayList.get(0) %>">
          <%=arrayList.get(0) %>
          </option>
      <%
          }
      %>
      </select>
      </td>
      <!-- 问题回显标识 -->
      <input type="text" id="problemback" value="<s:property value="problem"/>" class="inputTextNormal" style="display: none"/>
      <td class="tdFormText">问题:</td> 
      <td class="tdFormInput">
      <select id="problem" name="problem">
      <option selected="selected" value="">--请选择--</option>
      </select>
      </td>
      <!--期限回显标识 -->
      <input type="text" id="qxback" value="<s:property value="qixian"/>" class="inputTextNormal" style="display: none"/>
      <td class="tdFormText">保管期限:</td>
      <td class="tdFormInput">
      <select id="qixian" name="qixian">
          <option value="">--请选择--</option>
        <option value="永久" >永久</option>
        <option value="30年" >30年</option>
        <option value="10年" >10年</option>
        <option value="暂存" >暂存</option>
      </select>
      </td>
      <td class="tdFormText">文件形成日期:</td>
      <td class="tdFormInput"><input type="text" name="time1" class="inputTextNormal" value="<s:date name="time1" 
      format="yyyy-MM-dd" />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly"/>
                到
      <input type="text" name="time2" class="inputTextNormal" value="<s:date name="time2" 
      format="yyyy-MM-dd" />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly"/>
      </td>
      <!-- 排序回显标识 -->
      <input type="text" id="pxback" value="<s:property value="paixu"/>" class="inputTextNormal" style="display: none"/> 
      <td class="tdFormText">排序:</td>
      <td class="tdFormInput">
      <select name="paixu" id="paixu">
        <option value="paixu" selected>--请选择--</option>
        <option value="to_number"  >按件号</option> 
        <option value="fileNumber" >按文号</option>
        <option value="createrDate">按时间</option>
      </select>
      </td>
    </tr>
  </table>
  <!--底部按钮表格开始-->
  <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabMainBot">
    <tr>
      <td>    
          <input type="button" class="button1" value="查 询" name="searchButton" onclick="search()"/>
          <!-- <input name="buttonReset" type="button" class="button" value="重 置"/> -->
      </td>
    </tr>
  </table>
  <!--底部按钮表格结束-->
  </div> 
  <!--工具栏-->
  <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabMainTop">
    <tr>
      <td align="right">
        <input type="hidden" name="returnURL" value="listArchives.action?listBean.start=<s:if test="listBean==null">0&listBean.length=15</s:if><s:else><s:property value="listBean.start"/>&listBean.length=<s:property value="listBean.length"/></s:else>&id=<s:property value="id"/>&qzh=<s:property value="qzh"/>&dept=<s:property value="dept"/>&problem=<s:property value="problem"/>&timing=<s:property value="timing"/>&wenhao=<s:property value="wenhao"/>&zeren=<s:property value="zeren"/>&time1=<s:property value="time1"/>&time2=<s:property value="time2"/>&page=<s:property value="page"/>&hehao=<s:property value="hehao"/>&qixian=<s:property value="qixian"/>&zhutici=<s:property value="zhutici"/>&beizhu=<s:property value="beizhu"/>&danghao=<s:property value="danghao"/>&miji=<s:property value="miji"/>&sbjh=<s:property value="sbjh"/>&gbjh=<s:property value="gbjh"/>&cfwz=<s:property value="cfwz"/>&state=<s:property value="state"/>&url=<s:property value="url"/> "/>
        <input type="hidden" name="listBean.start" id="start"/>
        <a href="javascript:newArchives();" class="buttonBig"><img src="images/16B/new_image/gb_icon-add.png" /></a>
        <a href="javascript:deleteArchives();" class="buttonBig"><img src="images/16B/new_image/gb_icon-del.png" /></a>
        <!--  
        <input type="button" name="NewButton" value="新建" class="button" onclick="newArchives()"/>
        <input type="button" name="DeleteButton" value="删除" class="button" onclick="deleteArchives()"/>
        -->
      </td>
    </tr>
  </table>

  <!--列表-->
  <div class="discolor">
  <table width="98%" border="0" cellpadding="3" cellspacing="0" align="center" class="tabout" id="ArchivesTable">
    <tr>
      <th class="thListNormal" width="40"><a href="javascript:selectAll()" id="selectBox" class="tt">全选</a></th>
      <th class="thListNormal">保管期限</th>
      <th class="thListNormal">件号</th>
      <th class="thListNormal">责任者</th>
      <th class="thListNormal">文号</th>
      <th class="thListNormal">题名</th>
      <th class="thListNormal">文件形成日期</th>
      <th class="thListNormal">页数</th>
      <th class="thListNormal">备注</th>
      
      <th class="thListNormal">操作&nbsp;</th>
    </tr>
    <%boolean color = false;%>
    <s:iterator value="listBean.dataList">
    <%color = !color;%>
    <tr class="<%=color?"trcolor":"trwhite"%>">
      <td class="<%=color?"trcolor1":"trwhite1"%>"><input name="ids" type="checkbox" value="<s:property value="id"/>"/></td>
      <td class="<%=color?"trcolor1":"trwhite1"%>"><s:property value="qixian"/>&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>"><s:property value="sbjh"/>&nbsp;</td>
      <!-- 截取字符串的长度 -->
      <td class="<%=color?"trcolor1":"trwhite1"%>" title="<s:property value="zeren" />">
      <s:if test="zeren.length()>13">        
          <s:property value="zeren.substring(0,13)+'...'" />&nbsp;        
      </s:if>           
      <s:else>        
          <s:property value="zeren" />&nbsp;        
      </s:else>
      </td>
      <td class="<%=color?"trcolor1":"trwhite1"%>" title="<s:property value="wenhao" />">
      <s:if test="wenhao.length()>13">        
          <s:property value="wenhao.substring(0,13)+'...'" />&nbsp;        
      </s:if>           
      <s:else>        
          <s:property value="wenhao" />&nbsp;        
      </s:else>
      </td>
      <td class="<%=color?"trcolor1":"trwhite1"%>" title="<s:property value="timing" />">
      <s:if test="timing.length()>13">        
          <s:property value="timing.substring(0,13)+'...'" />&nbsp;        
      </s:if>           
      <s:else>        
          <s:property value="timing" />&nbsp;        
      </s:else>
      </td>
      <td class="<%=color?"trcolor1":"trwhite1"%>"><s:date name="time" format="yyyy-MM-dd"/>&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>"><s:property value="page"/>&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>" title="<s:property value="beizhu" />">
      <s:if test="beizhu.length()>13">        
          <s:property value="beizhu.substring(0,13)+'...'" />&nbsp;        
      </s:if>           
      <s:else>        
          <s:property value="beizhu" />&nbsp;        
      </s:else>
      </td>
      <td class="<%=color?"trcolor1":"trwhite1"%>"><a href="javascript:editArchives('<s:property value="id"/>')">查看/修改</a></td>
    </tr>
    </s:iterator>
    <!-----------空行填充------------->
    <s:bean name="org.apache.struts2.util.Counter" id="counter1">
      <s:param name="first" value="listBean.dataList.size+1" />
      <s:param name="last" value="listBean.length" />
    <s:iterator>
      <%color = !color;%>
      <tr class="<%=color?"trcolor":"trwhite"%>">
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      <td class="<%=color?"trcolor1":"trwhite1"%>">&nbsp;</td>
      </tr>
    </s:iterator>
    </s:bean>
  </table>
  </div>
  <!--翻页-->
  <table width="98%" border="0" cellpadding="2" cellspacing="0" align="center" class="tabMainBot">
    <tr >
      <td class="pageTd" >显示
      <select name="listBean.length" id="length" onchange="turnPage('<s:property value="listBean.start"/>')">
         <option value="<s:property value="listBean.length"/>" selected> 
         <s:property value="listBean.length"/></option> 
         <% for(int i=10;i<=50;i=i+5){
              out.println("<option value="+i+" >"+i+"</option>");
            }  %>
      </select>&nbsp;<s:property value="listBean.currPage"/>/<s:property value="listBean.maxPageCount"/>&nbsp;<s:property value="listBean.count"/>&nbsp;
      <s:if test="listBean.firstStart==-1">
      首页&nbsp;</s:if>
      <s:else><a href="javascript:turnPage('<s:property value="listBean.firstStart"/>')">首页</a>&nbsp;</s:else>
     <s:if test="listBean.previousStart==-1">
      上一页&nbsp;</s:if>
      <s:else>
      <a href="javascript:turnPage('<s:property value="listBean.previousStart"/>')">上一页</a>&nbsp;
      </s:else>
      <s:if test="listBean.nextStart==-1">
      下一页&nbsp;
      </s:if><s:else>
      <a href="javascript:turnPage('<s:property value="listBean.nextStart"/>')">下一页</a>&nbsp;
      </s:else>
      <s:if test="listBean.lastStart==-1">
      末页&nbsp;
      </s:if><s:else>
      <a href="javascript:turnPage('<s:property value="listBean.lastStart"/>')">末页</a>&nbsp;
      </s:else><input name="page" type="text" class="inputTextPage" size="3"/><a  href="javascript:goPage()">GO</a>
      </td>
    </tr>
  </table>
</form>
</body>
</html>
原文地址:https://www.cnblogs.com/is1988/p/2714863.html