Este artigo compartilha a tecnologia de redação de formulários para sua referência. O conteúdo específico é o seguinte
Escreva de volta para apoiar o Método JAr Spelling JS:
/ ** * Escreva o formulário de volta * * @param mrequest * @return */ public static string writebackMaptoForm (map mrequest) {return writebackMaptoForm (mrequest, new string [] {}, "writebackMaptoform"); } / ** * Escreva de volta * * @param mrequest * @param ignorename Definir qual entrada de valores -chave não escreve de volta * @return * / public static string writebackMaptoform (map mrequest, string [] ignorename, string jsnctionName) {mrequest.roMove ("checkbox_template,"); // Não escreva de volta o valor da caixa de seleção na lista 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 (); Objeto tempvalue = mrequest.get (tempkey); if (tempkey.startswith ("venus") || tempkey.startswith ("ranmin")) {continua; } if (rmstringhelper.arrayContainstring (ignorename, tempkey)) {continuação; } String tempvaluenew = ""; if (tempValue Instânciaof string) {// Se for um único valor, injete diretamente TempValuEnew = rmStringHelper.ReplacestringToScript ((String) tempValue); // Depois de retirá -lo do banco de dados, você precisa converter rtvalue.append ("indexArray [indexArray.length] =/" " + tempkey +"/";/n"); rtvalue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else if (tempValue Instância de string []) {// Se for um valor múltiplo, coloque na 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 +"/"] = ["); 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 Instância de registro de data e hora) {// Se for um registro de data e hora, injete diretamente se (tempValue == null) {continua; } tempvaluenew = rmStringHelper.ReplacestringToScript (tempValue.toString (). Substring (0,19)); rtvalue.append ("indexArray [indexArray.length] =/" " + tempkey +"/";/n"); rtvalue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else if (tempValue Instância de 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 ("Ao escrever a página, encontrei um tipo java desconhecido:" + tempvalue); } continuar; }} rtValue.append ("para (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 colocar o valor na solicitação no objeto mform var mform = new Object (); var indexArray = new Array (); função 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"] = "savexaminerule"; 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] = "proprietário_id"; mform ["proprietário_id"] = "s1"; for (var i = 0; i <indexArray.length; i ++) {writebackValue (indexArray [i]); }} writebackMaptoForm (); A saída chama o método JS após adicionar a chave JSP Página JSP: <Script Language = "JavaScript"> <% // Formulário Writeback if (request.getAttribute (renExamineconstants.request_write_back_form_values)! out.print (rmvohelper.writebackMaptoForm ((java.util.map) request.getAttribute (renExamineConstants.request_write_back_form_values))); // o script para a saída do método de writeback do formulário} map mapt = (java.util.map) request.getAttribute (renExamineconstants.request_write_back_form_values); System.out.print ("infois:"+mapt.entryset ()); out.print ("Alert (1);");%> </sCript> // O conteúdo do formato JS realmente injetado pela instrução acima é a seguinte: var mform = new Object (); var indexArray = new Array (); função 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 (); // Após a injeção, ligue para o método do formulário de writeback JS (WriteBackValue (inputName) {if (form.Elements [inputName] == undefined) {return false;} if (form.Elements [inputName] .Value! = Undefined) {form.Elements [inputName] .Value = mfore [inputname]; } if (form.Elements [inputName] .Length! = indefinido) {var thisValue = mform [inputName]; if (mform [inputName] [0] == indefinido) {thisValue = new Array (); thisValue [thisValue.length] = mform [inputName]; } if (form.Elements [inputName] .Length! = null) {var tempenngth = form.Elements [inputName] .Length; for (var j = 0; j <tempestunda; j ++) {var thisObj = form.Elements [inputName] [j]; for (var k = 0; k <thisValue.length; k ++) {if (thisObj.value == thisValue [k]) {if (thisObj.checked! = indefinido) {thisObj.checked = true; quebrar; } else if (thisObj.Selected! = indefinido) {thisObj.Selected = true; quebrar; }} else {if (thisObj.checked! = indefinido) {thisobj.checked = false; } else if (thisObj.Selected! = indefinido) {thisObj.Selected = false; }}}}}}}}}O exposto acima é tudo sobre este artigo, espero que seja útil para o aprendizado de todos.