Este artículo comparte tecnología de escritura de formulario para su referencia. El contenido específico es el siguiente
Escriba para apoyar el método Java Spelling JS:
/ ** * Formulario de redacción * * @param mrequest * @return */ public static string writingbackMapToForm (map mrequest) {return WritingMaptoForm (mrequest, new String [] {}, "WriteBackMaptoForm"); } / ** * Formulario de redacción * * @param mrequest * @param ignorename Definir qué entrada de valores clave no vuelve a escribir * @return * / public static string writingMapToForm (map mrequest, string [] IgnorEname, String JSFunctionNameNameName) {mrequest.remove ("Checkbox_template); // No vuelva a escribir el valor de la casilla de verificación en la lista StringBuffer rtValue = new StringBuffer (); rtValue.append ("var mform = new Object ();/n"); rtValue.append ("var indexArray = new Array ();/n"); rtValue.Append ("Function WritingMapToForm () {/n"); Iterador itmRequest = mrequest.keySet (). Iterator (); while (itmRequest.hasNext ()) {string tempkey = (string) itmRequest.next (); Objeto tempValue = mrequest.get (tempkey); if (tempkey.startswith ("Venus") || tempkey.Startswith ("ranmin")) {continuar; } if (rmStringHelper.ArrayContainString (ignorename, tempkey)) {continuar; } Cadena tempvaluene = ""; if (tempValue instanceOf string) {// Si es un solo valor, inyecte directamente tempvaluene = rmStringHelper.replacestringtoscript ((((string) tempValue); // Después de sacarlo de la base de datos, debe convertir rtValue.append ("indexArray [indexarray.length] =/" " + tempkey +"/";/n"); rtValue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else if (tempValue instanceOf string []) {// Si es un valor múltiple, ponte en la matriz 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 +"/"] = ["); para (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) {// Si es una marca de tiempo, inyectar directamente if (tempValue == null) {continuar; } tempvaluene = rmStringhelper.replacestringtost (TempValue.ToString (). Substring (0,19)); rtValue.append ("indexArray [indexArray.length] =/" " + tempkey +"/";/n"); rtValue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else if (tempvalue rtValue.append ("indexArray [indexArray.length] =/" " + tempkey +"/";/n"); rtValue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else {if (tempvalue! = null) {rmStringHelper.log ("Al volver a escribir la página, encontré un tipo de java desconocido:" + tempValue); } continuar; }} 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 (); } // Use este método para poner el valor en la solicitud en el objeto 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"] = "nulo"; indexArray [indexArray.length] = "propietario_id"; mform ["propietario_id"] = "S1"; for (var i = 0; i <indexArray.length; i ++) {WriteBackValue (indexArray [i]); }} WriteBackMaptoForm (); La salida llama al método JS después de agregar la página de instrucción clave JSP: <script language = "javascript"> <% // formulario de redacción if (request.getAttribute (RuleExamIneconStants.Request_Write_Back_Form_Values)! = NULL) {// Si el formulario de red out.print (rmVoHelper.WriteBackMaptoForm ((java.util.map) request.getAttribute (RuleExAmineConstants.Request_Write_Back_Form_Values))); // El script para producir el método de redacción de formulario} map mapt = (java.util.map) request.getAttribute (RuleExAmineConstants.Request_Write_Back_Form_Values); System.out.print ("Infois:"+mapt.entryset ()); out.print ("alerta (1);");%> </script> // El contenido de formato JS realmente inyectado por la instrucción anterior es el siguiente: var mform = new Object (); var indexArray = new Array (); function WriteBackMaptoForm () {indexArray [indexArray.length] = "_function_id_"; mform ["_ function_id_"] = "367021250000000000050"; indexArray [indexArray.length] = "cmd"; mform ["cmd"] = "listBusinessTypePage"; for (var i = 0; i <indexArray.length; i ++) {WriteBackValue (indexArray [i]); }} WriteBackMaptoForm (); // Después de la inyección, llame a la función del método de formulario de redacción de JS 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 templIgth = form.elements [inputName] .length; for (var j = 0; j <templIgth; j ++) {var thisObj = form.elements [inputName] [j]; for (var k = 0; k <thisSValue.length; k ++) {if (thisObj.Value == thisValue [k]) {if (thisObj.ecked! = Undefined) {thisObj.checked = true; romper; } else if (thisObj.selected! = Undefined) {thisObj.selected = true; romper; }} else {if (thisObj.ecked! = Undefined) {thisObj.ecked = false; } else if (thisObj.selected! = Undefined) {thisObj.selected = false; }}}}}}}}}Lo anterior se trata de este artículo, espero que sea útil para el aprendizaje de todos.