Form form write back technology Java implementation _java

Source: Internet
Author: User
Tags stringbuffer

The example of this article for everyone to share the form of form back to write technology for your reference, the specific contents are as follows

Write back the supported Java spelling JS method:

 /** * Writeback form * * @param mrequest * @return/public static String Writebackmaptoform (Map mrequest) {
  Return Writebackmaptoform (Mrequest, New string[]{}, "Writebackmaptoform"); /** * Write Back form * * @param mrequest * @param ignorename define which key values of input does not write back * @return/public static St Ring Writebackmaptoform (Map mrequest, string[] ignorename, String jsfunctionname) {mrequest.remove ("checkbox_template ");
    Do not write back the value of the checkbox in the list 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) {//If it is a single value, direct injection of tempvaluenew = Rmstringhelper.replacestringtoscript ((String) TEMPVA Lue);
        After taking out from the database need to convert 1 times rtvalue.append ("indexarray[indexarray.length] = \" "+ Tempkey +" \ \ n ");
      Rtvalue.append ("mform[\" "+ Tempkey +" \ "] = \" "+ tempvaluenew +" \ "; \ n"); else if (Tempvalue instanceof string[]) {//If it is multi-valued, put the array rtvalue.append ("indexarray[indexarray.length] = \" "" + t
        Empkey + "\"; \ 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 it is a timestamp, directly inject 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.tostrin
    g ());
    Rtvalue.append ("indexarray[indexarray.length] = \" "+ Tempkey +" \ \ n ");
      Rtvalue.append ("mform[\" "+ Tempkey +" \ "] = \" "+ tempvaluenew +" \ "; \ n"); } else {if (tempvalue!= null) {RmStringHelper.log ("inWhen the page was written back, an unknown Java type was encountered: "+ 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 ();
 ///This method puts the value in the request into the Mform object 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 (); Key Statement JSP page is added after the output calls the JS method: <script language= "JavaScript" > <%//form writeback if (Request.getattribute ( ruleexamineconstants.request_write_back_form_values)!= null) {//If the form writeback bean taken out in REQUEST is not empty out.print ( Rmvohelper.writebackmaptoform (JAVA.UTIL.MAP) Request.getattribute (ruleexamineconstants.request_write_back_form _values))); Script for Output form writeback method} Map mapt = (java.util.Map) request.getattribute (ruleexamineconstants.request_write_back_form_values)
 ;
 System.out.print ("Infois:" +mapt.entryset ());
Out.print ("alert (1);");
 %> </script>//The above statement actually injects the JS format content such as: 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 (); Call JS Writeback form method function Writebackvalue (InputName) {if (form.elements[inputname] = = undefined) {return false;} if (form) after injection     
. 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.CHEC 
            ked = 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; }  
          }
        }
      }
    }  
           
  }
}

The above is the entire content of this article, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.