struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-struts/web/test/test/org/apache/struts/taglib/html TestFormTag1.jsp
Date Mon, 10 Mar 2003 01:57:31 GMT
craigmcc    2003/03/09 17:57:31

  Modified:    src/share/org/apache/struts/taglib/html FormTag.java
                        JavascriptValidatorTag.java
               web/test/test/org/apache/struts/taglib/html TestFormTag1.jsp
  Log:
  Clean up the JavaScript code generation to not use string concatenation,
  and make the line-end generation platform independent so that Cactus tests
  can pass on Linux.
  
  Revision  Changes    Path
  1.45      +46 -21    jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java
  
  Index: FormTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- FormTag.java	8 Mar 2003 19:23:49 -0000	1.44
  +++ FormTag.java	10 Mar 2003 01:57:30 -0000	1.45
  @@ -125,6 +125,11 @@
       protected String focusIndex = null;
   
       /**
  +     * The line ending string.
  +     */
  +    protected static String lineEnd = System.getProperty("line.separator");
  +
  +    /**
        * The ActionMapping defining where we will be submitting this form
        */
       protected ActionMapping mapping = null;
  @@ -629,35 +634,56 @@
   
           // Render JavaScript to set the input focus if required
           if (this.focus != null) {
  -            results.append("\r\n");
  +
  +            results.append(lineEnd);
               results.append(this.getJsStartElement());
   
               // xhtml script content shouldn't use the browser hiding trick
               if (!this.isXhtml()) {
  -                results.append("  <!--\r\n");
  +                results.append("  <!--");
  +                results.append(lineEnd);
               }
   
               // Construct the control name that will receive focus.
               // This does not include any index.
  -            String focusControl =
  -                "document.forms[\"" + beanName + "\"].elements[\"" + this.focus + "\"]";
  +            StringBuffer focusControl = new StringBuffer("document.forms[\"");
  +            focusControl.append(beanName);
  +            focusControl.append("\"].elements[\"");
  +            focusControl.append(this.focus);
  +            focusControl.append("\"]");
  +
  +            results.append("  var focusControl = ");
  +            results.append(focusControl.toString());
  +            results.append(";");
  +            results.append(lineEnd);
  +            results.append(lineEnd);
   
  -            results.append("  var focusControl = " + focusControl + ";\r\n\r\n");
  -
  -            results.append("  if (focusControl.type != \"hidden\") {\r\n");
  +            results.append("  if (focusControl.type != \"hidden\") {");
  +            results.append(lineEnd);
   
               // Construct the index if needed and insert into focus statement
               String index = "";
               if (this.focusIndex != null) {
  -                index = "[" + this.focusIndex + "]";
  +                StringBuffer sb = new StringBuffer("[");
  +                sb.append(this.focusIndex);
  +                sb.append("]");
  +                index = sb.toString();
               }
  -            results.append("     focusControl" + index + ".focus();\r\n  } \r\n");
  +            results.append("     focusControl");
  +            results.append(index);
  +            results.append(".focus();");
  +            results.append(lineEnd);
  +
  +            results.append("  }");
  +            results.append(lineEnd);
   
               if (!this.isXhtml()) {
  -                results.append("  // -->\r\n");
  +                results.append("  // -->");
  +                results.append(lineEnd);
               }
   
  -            results.append("</script>\r\n");
  +            results.append("</script>");
  +            results.append(lineEnd);
           }
   
           // Print this value to our output writer
  @@ -763,14 +789,13 @@
        * Returns the starting javascript element formatted for xhtml if needed.
        */
       private String getJsStartElement() {
  -        String start = "<script type=\"text/javascript\"";
  -
  +        StringBuffer sb = new StringBuffer("<script type=\"text/javascript\"");
           if (!this.isXhtml()) {
  -            start += " language=\"JavaScript\"";
  +            sb.append(" language=\"JavaScript\"");
           }
  -        start += ">\r\n";
  -
  -        return start;
  +        sb.append(">");
  +        sb.append(lineEnd);
  +        return sb.toString();
       }
   
       /**
  
  
  
  1.24      +9 -4      jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java
  
  Index: JavascriptValidatorTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- JavascriptValidatorTag.java	8 Mar 2003 19:23:49 -0000	1.23
  +++ JavascriptValidatorTag.java	10 Mar 2003 01:57:31 -0000	1.24
  @@ -118,6 +118,11 @@
       protected String formName = null;
   
       /**
  +     * The line ending string.
  +     */
  +    protected static String lineEnd = System.getProperty("line.separator");
  +
  +    /**
        * The current page number of a multi-part form.
        * Only valid when the formName attribute is set.
        */
  
  
  
  1.2       +3 -3      jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestFormTag1.jsp
  
  Index: TestFormTag1.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/test/test/org/apache/struts/taglib/html/TestFormTag1.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestFormTag1.jsp	7 Mar 2003 05:38:24 -0000	1.1
  +++ TestFormTag1.jsp	10 Mar 2003 01:57:31 -0000	1.2
  @@ -43,7 +43,7 @@
   
     if (focusControl.type != "hidden") {
        focusControl.focus();
  -  } 
  +  }
     // -->
   </script>
   	</bean:define>
  @@ -64,7 +64,7 @@
   
     if (focusControl.type != "hidden") {
        focusControl[2].focus();
  -  } 
  +  }
     // -->
   </script>
   	</bean:define>
  @@ -215,4 +215,4 @@
   }
   	
   Assert.assertEquals(compareTo, expected);
  -%>
  \ No newline at end of file
  +%>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Mime
View raw message