程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> form表單回寫技巧java完成

form表單回寫技巧java完成

編輯:關於JAVA

form表單回寫技巧java完成。本站提示廣大學習愛好者:(form表單回寫技巧java完成)文章只能為提供參考,不一定能成為您想要的結果。以下是form表單回寫技巧java完成正文


本文實例為年夜家分享了form表單回寫技巧,供年夜家參考,詳細內容以下

回寫支撐的java拼js的辦法:

 /**
   * 回寫表單
   *
   * @param mRequest
   * @return
   */
  public static String writeBackMapToForm(Map mRequest) {
    return writeBackMapToForm(mRequest, new String[]{}, "writeBackMapToForm");
  }
  /**
   * 回寫表單
   *
   * @param mRequest
   * @param ignoreName 界說哪些key值的input不回寫
   * @return
   */
  public static String writeBackMapToForm(Map mRequest, String[] ignoreName, String jsFunctionName) {
  mRequest.remove("checkbox_template"); //不回寫列表中checkbox的值
    StringBuffer rtValue = new StringBuffer();
    rtValue.append(" var mForm = new Object();\n");
    rtValue.append(" var indexArray = new Array();\n");
    rtValue.append(" function writeBackMapToForm() {\n");
    Iterator itMRequest = mRequest.keySet().iterator();
    while (itMRequest.hasNext()) {
      String tempKey = (String) itMRequest.next();
      Object tempValue = mRequest.get(tempKey);
      if (tempKey.startsWith("VENUS") || tempKey.startsWith("RANMIN")) {
        continue;        
      }
      if (RmStringHelper.ArrayContainString(ignoreName, tempKey)) {
        continue;        
      }
      String tempValueNew = "";
      if (tempValue instanceof String) { //假如是單值,直接注入
        tempValueNew = RmStringHelper.replaceStringToScript((String)tempValue); //從數據庫中掏出來今後須要轉換1次
        rtValue.append("  indexArray[indexArray.length] = \"" + tempKey + "\";\n");
        rtValue.append("  mForm[\"" + tempKey + "\"] = \"" + tempValueNew + "\";\n");
      } else if (tempValue instanceof String[]) { //假如是多值,放入數組
        rtValue.append("  indexArray[indexArray.length] = \"" + tempKey + "\";\n");
        String[] myArray = (String[]) tempValue;
        if ( tempKey.equals("cmd") ){
          tempValueNew = RmStringHelper.replaceStringToScript(myArray[0]);
          rtValue.append("  mForm[\"" + tempKey + "\"] = \"" + tempValueNew + "\";\n");
        } else {
          rtValue.append("  mForm[\"" + tempKey + "\"] = [");
          for (int i = 0; i < myArray.length; i++) {
            if (i > 0)
              rtValue.append(",");
            tempValueNew = RmStringHelper.replaceStringToScript(myArray[i]);
            rtValue.append("\"" + tempValueNew + "\"");
          }
          rtValue.append("];\n");
        }
      } else if (tempValue instanceof Timestamp) { //假如是時光戳,直接注入
        if(tempValue == null) {
          continue;
        }
        tempValueNew = RmStringHelper.replaceStringToScript(tempValue.toString().substring(0,19));
        rtValue.append("  indexArray[indexArray.length] = \"" + tempKey + "\";\n");
        rtValue.append("  mForm[\"" + tempKey + "\"] = \"" + tempValueNew + "\";\n");
      } else if (tempValue instanceof BigDecimal){
        tempValueNew = RmStringHelper.replaceStringToScript(tempValue.toString());
    rtValue.append("  indexArray[indexArray.length] = \""
        + tempKey + "\";\n");
    rtValue.append("  mForm[\"" + tempKey + "\"] = \""
        + tempValueNew + "\";\n");
      } else {
        if(tempValue != null) {
          RmStringHelper.log("在回寫頁面時,碰到了未知java類型:" + tempValue);          
        }
        continue;
      }
    }
    rtValue.append("  for(var i=0; i<indexArray.length; i++) {\n");
    rtValue.append("   writeBackValue(indexArray[i]);\n");
    rtValue.append("  }\n");
    rtValue.append(" }\n");
    rtValue.append(jsFunctionName + "();\n");
    return rtValue.toString();
  }
//經由過程此辦法將request中的值放入mForm對象中
var mForm = new Object();
 var indexArray = new Array();
 function writeBackMapToForm() {
  indexArray[indexArray.length] = "att_id";
  mForm["att_id"] = "";
  indexArray[indexArray.length] = "businessTypeOID";
  mForm["businessTypeOID"] = [""];
  indexArray[indexArray.length] = "business_type1";
  mForm["business_type1"] = "";
  indexArray[indexArray.length] = "business_type2";
  mForm["business_type2"] = "1";
  indexArray[indexArray.length] = "cmd";
  mForm["cmd"] = "saveExamineRule";
  indexArray[indexArray.length] = "document_content";
  mForm["document_content"] = "s2";
  indexArray[indexArray.length] = "file_path";
  mForm["file_path"] = "";
  indexArray[indexArray.length] = "file_template";
  mForm["file_template"] = "";
  indexArray[indexArray.length] = "gxl";
  mForm["gxl"] = "null";
  indexArray[indexArray.length] = "owner_id";
  mForm["owner_id"] = "s1";
  for(var i=0; i<indexArray.length; i++) {
   writeBackValue(indexArray[i]);
  }
 }
writeBackMapToForm();
 
症結語句jsp頁面中參加後輸入挪用js辦法:
 
<script language="javascript">
<% //表單回寫
  if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //假如request中掏出的表單回寫bean不為空
    out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //輸入表單回寫辦法的劇本
  }
 Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES);
 System.out.print("infois:"+mapt.entrySet());
 out.print("alert(1);");
%>
</script>
 
//下面語句現實上注入的js格局內容如:
var mForm = new Object();
 var indexArray = new Array();
 function writeBackMapToForm() {
  indexArray[indexArray.length] = "_function_id_";
  mForm["_function_id_"] = "3670212500000000050";
  indexArray[indexArray.length] = "cmd";
  mForm["cmd"] = "listBusinessTypePage";
  for(var i=0; i<indexArray.length; i++) {
   writeBackValue(indexArray[i]);
  }
 }
writeBackMapToForm();
 
  
 
 
 
//注入後挪用js回寫表雙方法
function writeBackValue(inputName) {
if(form.elements[inputName] == undefined) {
  return false;
}
if(form.elements[inputName].value != undefined) { 
  form.elements[inputName].value = mForm[inputName];     
} 
if(form.elements[inputName].length != undefined ) { 
  var thisValue = mForm[inputName];
  if(mForm[inputName][0] == undefined) {
    thisValue = new Array();
    thisValue[thisValue.length] = mForm[inputName];             
  }
  if(form.elements[inputName].length != null) { 
    var tempLength = form.elements[inputName].length;
    for(var j=0; j<tempLength; j++) {
      var thisObj = form.elements[inputName][j];
      for(var k=0; k<thisValue.length; k++) {
        if(thisObj.value == thisValue[k]) { 
          if( thisObj.checked != undefined) {
            thisObj.checked = true; 
            break;                 
          } else if( thisObj.selected != undefined) {
            thisObj.selected = true;                
            break;
          }
        } else {               
          if( thisObj.checked != undefined) {
            thisObj.checked = false;  
          } else if( thisObj.selected != undefined) {
            thisObj.selected = false;                
            }  
          }
        }
      }
    }  
           
  }
}

以上就是本文的全體內容,願望對年夜家的進修有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved