同暢にいる時のコード

Posted on 2006-11-29 13:54 wbq-123 阅读(216) 评论(0)  编辑  收藏

  
  String[] selects = request.getParameterValues("check1");
  StringBuffer bf = new StringBuffer();
  
  for (int i = 0; i < selects.length; i++) {
   if (0 < i) {
    bf.append(",");
   }
   bf.append(selects[i]);
  }
  
//tab  index
//  if ("".endsWith(aForm.getTabIndex())) {
   aForm.setTabIndex("0");
//  }

  try {
   // 取得对象
   List list = aBean.getList();

   aForm.setSelects(bf.toString());
   aForm.setMaxPage(selects.length);
   aForm.setNowPage(1);
   
   aForm.setList((List)list.get(Integer.parseInt(selects[0])));
//   request.setAttribute("data", list.get(Integer.parseInt(selects[0])));
   
   aForm.setHyoukaList(aBean.getHyoukaList());
   // 取得综合评价表
   aForm.setSougouHyoukaList(aBean.getSougouHyoukaList());
  } catch (BaseException e) {
   e.printStackTrace();
   request.setAttribute(ERROR_MSG, e.toString());
   return (mapping.findForward(NG_ERROR));
  }

  trace.debug("-----K1104HyoukaShaInputAction perform End    -----");
  // 结果返回给FRAMEWORK
  return (mapping.findForward(OK_SUCCESS));
 }
}

  
   if (sheet.getStaffInfo().getMtOrg().getOrgRank() == 3) {
    org2 =sheet.getStaffInfo().getMtOrg().getParentOrg().getOrgName();
   }
   
   if (sheet.getStaffInfo().getMtOrg().getOrgRank() == 3) {
    org2 =sheet.getStaffInfo().getMtOrg().getParentOrg().getOrgName();
    org3 =sheet.getStaffInfo().getMtOrg().getParentOrg().getParentOrg().getOrgName();
   }
***********************************************************************

//  Date fromDate = new Date(System.currentTimeMillis());
//  
//  Calendar cal=Calendar.getInstance();
//  
//  String year=Integer.toString(cal.get(Calendar.YEAR));
//  
//  String month=Integer.toString(cal.get(Calendar.MONTH)+1);
//  
//  String y=cal.getTime().toString();
//  
//   java.text.SimpleDateFormat f=new java.text.SimpleDateFormat("yyyy--MM--dd--hh--mm--ss--");
//  
//   String m= f.format(cal.getTime());

//  Date dateFrom= java.sql.Date.valueOf("2002/10/10");

//  Date dateTo= java.sql.Date.valueOf("2008/10/10");

SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");

*******************************************************************************
(table) --list.jsp
<%
 StringBuffer re = new StringBuffer();

 List l = (List) request.getAttribute("list");
 
 System.out.print(flg);

 re.append("<table cellSpacing='1' cellPadding='0' bgcolor='#999999' border='0'>");
 for (Iterator iter = l.iterator(); iter.hasNext();) {

  if (iter.next() instanceof K0401ShinKiData) {
   K0401ShinKiData item = (K0401ShinKiData) iter.next();
   re.append("<tr bgcolor='#FFFFFF'>");
   // org target
   if ("0".equals(flg)) {
    re.append("<input type='hidden' name='orgTargetIds' value='");
    re.append(item.getOrgTargetId());
    re.append("'/>");
    re.append("<input type='hidden' name='orgTargetNums' value='");
    re.append(item.getOrgTargetNum());
    re.append("'/>");
  
    re.append("<td width='20' align='center'>");
    re.append(item.getOrgTargetNum());
    re.append("&nbsp;</td><td>");
    re.append(item.getSoshikiNaiyo());

   }
   // other  org target
   else {
    re.append("<input type='hidden' name='otherorgTargetIds' value='");
    re.append(item.getOtherOrgTargetId());
    re.append("'/>");
    re.append("<input type='hidden' name='otherorgTargetNums' value='");
    re.append(item.getOtherOrgTargetNum());
    re.append("'/>");
  
    re.append("<td width='20' align='center'>");
    re.append(item.getOtherOrgTargetNum());
    re.append("&nbsp;</td><td>");
    re.append(item.getSonotaNaiyo());
   }
   
   re.append("&nbsp;</td></tr>");
  }
 }
 re.append("</table>");

 out.clear();
 out.print(re.toString());
%>
*****************************************************************************
js
-----------creat a xmlhttp object--------------
   function newXMLHttpRequest() {
  /* Create a new XMLHttpRequest object to talk to the Web server */
  var xmlHttp = false;
  if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
   xmlHttp = new XMLHttpRequest();
  }
     return xmlHttp;
 }
***************************************************************************
js
-------------creat a server-------------

    /**
     * send request to server.
     * @params serviceName
     * @methods methodName    
     * @params params
     * @mode :options|table
     */
 function callListServer(xmlHttp, serviceName, method, params, mode) {
  
  params = params.toString();
  // Build the URL to connect to
  var root = "http://localhost:8080/kawa/";
  var url = root + "AJAXList.do?serviceName="+serviceName + "&params=" + params + "&method=" + method  + "&mode=" + mode;
  
  // Open a connection to the server
  xmlHttp.open("GET", url, false);
   
        // Send the request
  xmlHttp.send(null);
 }

*********************************************************************************
js in the K0401.jsp (first jsp)
------------return the value to a jsp ---------------
   var objName = "divOrgTaget";
   var methodName = "findK0401OrgTargets";
   var params = new Array(staffId, outsideOrgCode);
   updateTable(objName, serviceName, methodName ,params );
   
   var orgTagetSetter = document.getElementById("orgTagetSetter");
   orgTagetSetter.innerHTML = hosyokuName + "<br>" + staffName; 
   var width= 510;
   var orgOutSidetable = document.getElementById(objName);
   orgOutSidetable.width= width; //orgOutSidetable.parentNode.style.width + 5;

*********************************************************************************
AjaxListAction

-----------
/**
 *
 */
package common.ajax;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import service.IK04Service;
import service.IK15Service;

import common.exception.BaseException;
import common.log.ITraceLogger;
import common.log.TraceLogger;
import common.util.BaseAction;
import common.util.Constant;

/**
 * get ajax list.
 * @author shilei
 */
public class AJAXListAction extends BaseAction {
 public ActionForward perform(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws IOException, ServletException, BaseException {
  ITraceLogger trace = new TraceLogger();
  trace.debug("-----AJAXOptionsAction perform Start  -----");
  String[] params = request.getParameter("params").split(",");
//  Object[] params = null;//(Object[])
  
  String serviceName = request.getParameter("serviceName");
  String methodName = request.getParameter("method");
  String mode = request.getParameter("mode");

  List reList = null;
  try {
   // build method
   Method method = null;
   // get service bean
   if(serviceName.equals("K04Service")) {
    IK04Service service = (IK04Service) this.getWebApplicationContext().getBean(serviceName);
    if(1 == params.length) {
     method = service.getClass().getMethod(methodName, new Class[] { String.class });
    }
    if(2 == params.length) {
     method = service.getClass().getMethod(methodName, new Class[] { String.class, String.class });
    } 
    // invoke method
    reList = (List) method.invoke(service, params);
   } else {
    IK15Service service = (IK15Service) this.getWebApplicationContext().getBean(serviceName);
    if(1 == params.length) {
     method = service.getClass().getMethod(methodName, new Class[] { String.class });
    }
    if(2 == params.length) {
     method = service.getClass().getMethod(methodName, new Class[] { String.class, String.class });
    } 
    // invoke method
    reList = (List) method.invoke(service, params);
   }   

   reList.toArray();

  } catch (SecurityException e) {
   throw new BaseException("SecurityException", e);
  } catch (IllegalArgumentException e) {
   throw new BaseException("IllegalArgumentException", e);
  } catch (NoSuchMethodException e) {
   throw new BaseException("NoSuchMethodException", e);
  } catch (IllegalAccessException e) {
   throw new BaseException("IllegalAccessException", e);
  } catch (InvocationTargetException e) {
   e.printStackTrace();
   throw new BaseException("InvocationTargetException", e);
  }

  request.setAttribute("list", reList);
  
  request.setAttribute("flg", Constant.FLAG_FALSE);
  if("findK0401OrgTargetOther".equals(methodName)) {
   request.setAttribute("flg", Constant.FLAG_TRUE);
  }  
  
  String aForward = "";
  if("options".equals(mode)) {
   aForward = "options";
  } else if("table".equals(mode)) {
   aForward = "table";
  }
  
  trace.debug("-----AJAXOptionsAction perform End    -----");
  return mapping.findForward(aForward);
 }
}
-----------
*************************************************************************

Option.jsp
----------return string to this jsp-
<%
 StringBuffer re = new StringBuffer();
 List l = (List) request.getAttribute("list");

 int index = 1;
 for (Iterator iter = l.iterator(); iter.hasNext();) {
  Select select = (Select) iter.next();
  if (index > 1) {
   re.append("/");
  }
  re.append(select.getValue() + "," + select.getLabel());
  index++;
 }

 out.clear();
 out.print(re.toString());
%>
**********************************************************************

 /**
  * init options
  * @param flg (true:update many selects; false: update one select)
  */
 function initOptions(flg) {
  var xmlHttp = newXMLHttpRequest();
  
  if(!selectValues[0]) {  
   if(flg) {
    updateManyOptions("0", -1)
   } else {
    updateOneOptions("0", -1)
   }
  } else {
   for(var i=0; i<selectValues.length; i++) {
    if(selectValues[i]) {
     if(0 == i) {
      updateOneOptions("0", -1); 
      updateOneOptions(selectValues[i], 0); 
     } else if(i < selectValues.length - 1) {
      updateOneOptions(selectValues[i], i);
     }
    }
    var objHTML = eval("document.forms[0]." + selects[i]);
    objHTML.value=selectValues[i];
   }
  }
 }


 @_@


 /**
  *update many options
  *@param parentCode code of the current node
  *@param rank rank of the current node
 */
 function updateManyOptions(parentCode, rank) {
  var xmlHttp = newXMLHttpRequest();

  // new Array
  var newMethods = methods.slice(rank*1 +1, methods.length);
   
  callMenuServer(xmlHttp, parentCode, newMethods);

  if (xmlHttp.readyState == 4) {
     var ret = xmlHttp.responseText;
    
     var arrRet = ret.split("|");
   
   var index = 0;
   for(var i=rank*1 + 1; i<selects.length; i++) {
    var objHTML = eval("document.forms[0]." + selects[i]);
    if(objHTML) {
     if(index < arrRet.length) {
          setOptions(objHTML, arrRet[index]);
     } else {
       setOptions(objHTML, "");
     }
     index++;
    }
   }
  }
 }
 
 var OPTION_ALL = "all,";
 var OPTION_NONE = ",";
 
 /**
  *update one options
  *@param parentCode code of the current node
  *@param rank rank of the current node
 */
 function updateOneOptions(parentCode, rank) {
  var xmlHttp = newXMLHttpRequest();
  if(!parentCode) {
   for(var i=rank*1 + 1; i<selects.length; i++) {
    var objHTML = eval("document.forms[0]." + selects[i]);
    if(objHTML) {
//     setOptions(objHTML, ",--all--");
     setOptions(objHTML, OPTION_NONE);
    }
   }
   return;
  }
  
  // new Array
  var newMethods = methods[rank*1 + 1];
  
  callMenuServer(xmlHttp, parentCode, newMethods);

  if (xmlHttp.readyState == 4) {
      var ret = xmlHttp.responseText;
      for(var i=rank*1 + 1; i<selects.length; i++) {
    var objHTML = eval("document.forms[0]." + selects[i]);
    
    if(objHTML) {
     if(i == (rank*1 + 1) && !isEmpty(ret)) {
//          setOptions(objHTML, ",--all--/" + ret);
         
       if(-1 == rank) {
           setOptions(objHTML, OPTION_NONE + "/" + ret);
          } else {
           setOptions(objHTML, OPTION_NONE + "/" + ret + "/" + OPTION_ALL);
          }
     } else {
//       setOptions(objHTML, ",--all--");
       setOptions(objHTML, OPTION_NONE);
     }
    }
   }
  }
 }
 *********************************************************************
jsp’†onchange‘€ì?’ö:
 /**
  *update one options
  *@param parentCode code of the current node
  *@param rank rank of the current node
 */
 function updateOneOptions(parentCode, rank) {
  var xmlHttp = newXMLHttpRequest();
  if(!parentCode) {
   for(var i=rank*1 + 1; i<selects.length; i++) {
    var objHTML = eval("document.forms[0]." + selects[i]);
    if(objHTML) {
//     setOptions(objHTML, ",--all--");
     setOptions(objHTML, OPTION_NONE);
    }
   }
   return;
  }
  
  // new Array
  var newMethods = methods[rank*1 + 1];
  
  callMenuServer(xmlHttp, parentCode, newMethods);

  if (xmlHttp.readyState == 4) {
      var ret = xmlHttp.responseText;
      for(var i=rank*1 + 1; i<selects.length; i++) {
    var objHTML = eval("document.forms[0]." + selects[i]);
    
    if(objHTML) {
     if(i == (rank*1 + 1) && !isEmpty(ret)) {
//          setOptions(objHTML, ",--all--/" + ret);
         
       if(-1 == rank) {
           setOptions(objHTML, OPTION_NONE + "/" + ret);
          } else {
           setOptions(objHTML, OPTION_NONE + "/" + ret + "/" + OPTION_ALL);
          }
     } else {
//       setOptions(objHTML, ",--all--");
       setOptions(objHTML, OPTION_NONE);
     }
    }
   }
  }
 }
 ************************************************************
 logout.js


 updateUserPowerLogo(parent.head, <bean:write name="MainMenuInfo" property="userPower"/>);
 parent.document.title = "<%= MENU_NAME.toString().replaceAll("(<[^>]*>)+?"," ") %>";
 resetTimer();
 document.onkeypress = eventHandler;
 document.onmousemove = eventHandler;

 var countDown = 10 * 30 * 1000 ; // seconds
 var sessionTimer;
 
 function resetTimer() {
  clearTimeout(sessionTimer);
  sessionTimer = setTimeout("timeoutLogout()", countDown);
 }
 
 var customLogout;
 
 function timeoutLogout() {
  //alert("customLogout");
  if(customLogout) {
   //alert("Custom logout!");
   customLogout();
  }
  else
   defaultLogout();
 }
 
 function eventHandler(event) {
  resetTimer();
  return true;
 }
 
 function defaultLogout() {
  //alert("Default logout!");
  //parent.head.document.forms[0].target = "_top";
  //parent.head.document.forms[0].target = "SilentLogout.do";
  //parent.head.document.forms[0].submit();
  document.location = "AutoLogout.do";
  //parent.close();
 }

 ************************************************************

 

posts - 2, comments - 0, trackbacks - 0, articles - 0

Copyright © wbq-123