javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-116

Colon's not allowed in javascript function name

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      116

      Description

      I'm attempting to test port the latest 1.2 in a project I've developed in 1.1_01
      and I found a problem with forms inside of subviews. It appears that 1.2
      attempts to create a javascript function called "clearFormHiddenParams_<id of
      form here>" The problem is if the form exists in a sub form then the id of the
      form will have a ':' in it and javascript function names cannot have ':' in
      them. Below is a test case. If I click on the link then nothing happens and I
      get a javascript error.

      <%@ page language="java" %>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <f:view>
      <f:subview id="subview">
      <h:form id="form">
      <h:commandLink><h:outputText value="link"/></h:commandLink>
      </h:form>
      </f:subview>
      </f:view>

        Activity

        Hide
        youngm added a comment -

        Here is a quick patch I put together that fixes the problem. Although maybe not
        the best solution it may work for others with the same problem until you guys
        get a chance to look into it.

        Mike

        Index: src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java,v
        retrieving revision 1.82
        diff -u -r1.82 ButtonRenderer.java
        — ButtonRenderer.java 22 Mar 2005 22:31:27 -0000 1.82
        +++ ButtonRenderer.java 15 Apr 2005 01:08:21 -0000
        @@ -17,6 +17,7 @@

        import javax.faces.component.UICommand;
        import javax.faces.component.UIComponent;
        +import javax.faces.component.NamingContainer;
        import javax.faces.context.FacesContext;
        import javax.faces.context.ResponseWriter;
        import javax.faces.event.ActionEvent;
        @@ -182,7 +183,7 @@
        // parameters in the form.
        sb.append(CLEAR_HIDDEN_FIELD_FN_NAME);
        if (formClientId != null)

        { - sb.append("_" + formClientId); + sb.append("_" + formClientId.replace(NamingContainer.SEPARATOR_CHAR, '_')); }

        sb.append("(this.form.id);");
        // append user specified script for onclick if any.
        Index: src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java,v
        retrieving revision 1.26
        diff -u -r1.26 CommandLinkRenderer.java
        — CommandLinkRenderer.java 16 Dec 2004 17:56:37 -0000 1.26
        +++ CommandLinkRenderer.java 15 Apr 2005 01:08:21 -0000
        @@ -174,7 +174,7 @@
        sb = new StringBuffer();
        // call the javascript function that clears the all the hidden field
        // parameters in the form.

        • sb.append(CLEAR_HIDDEN_FIELD_FN_NAME + "_" + formClientId);
          + sb.append(CLEAR_HIDDEN_FIELD_FN_NAME + "_" +
          formClientId.replace(NamingContainer.SEPARATOR_CHAR, '_'));
          sb.append("('");
          sb.append(formClientId);
          sb.append("');");
          Index: src/com/sun/faces/renderkit/html_basic/FormRenderer.java
          ===================================================================
          RCS file:
          /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/FormRenderer.java,v
          retrieving revision 1.83
          diff -u -r1.83 FormRenderer.java
            • FormRenderer.java 10 Mar 2005 21:39:15 -0000 1.83
              +++ FormRenderer.java 15 Apr 2005 01:08:21 -0000
              @@ -18,6 +18,7 @@

        import javax.faces.component.UIComponent;
        import javax.faces.component.UIForm;
        +import javax.faces.component.NamingContainer;
        import javax.faces.context.FacesContext;
        import javax.faces.context.ResponseWriter;

        @@ -295,7 +296,7 @@
        writer.writeAttribute(SCRIPT_TYPE, "text/javascript", null);
        writer.write("\n<!--");
        writer.write("\nfunction ");

        • String functionName = (CLEAR_HIDDEN_FIELD_FN_NAME + "_" + formName);
          + String functionName = (CLEAR_HIDDEN_FIELD_FN_NAME + "_" +
          formName.replace(NamingContainer.SEPARATOR_CHAR, '_'));
          writer.write(functionName);
          writer.write("(curFormName) {");
          writer.write("\n var curForm = document.forms[curFormName];");
        Show
        youngm added a comment - Here is a quick patch I put together that fixes the problem. Although maybe not the best solution it may work for others with the same problem until you guys get a chance to look into it. Mike Index: src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java,v retrieving revision 1.82 diff -u -r1.82 ButtonRenderer.java — ButtonRenderer.java 22 Mar 2005 22:31:27 -0000 1.82 +++ ButtonRenderer.java 15 Apr 2005 01:08:21 -0000 @@ -17,6 +17,7 @@ import javax.faces.component.UICommand; import javax.faces.component.UIComponent; +import javax.faces.component.NamingContainer; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.event.ActionEvent; @@ -182,7 +183,7 @@ // parameters in the form. sb.append(CLEAR_HIDDEN_FIELD_FN_NAME); if (formClientId != null) { - sb.append("_" + formClientId); + sb.append("_" + formClientId.replace(NamingContainer.SEPARATOR_CHAR, '_')); } sb.append("(this.form.id);"); // append user specified script for onclick if any. Index: src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java,v retrieving revision 1.26 diff -u -r1.26 CommandLinkRenderer.java — CommandLinkRenderer.java 16 Dec 2004 17:56:37 -0000 1.26 +++ CommandLinkRenderer.java 15 Apr 2005 01:08:21 -0000 @@ -174,7 +174,7 @@ sb = new StringBuffer(); // call the javascript function that clears the all the hidden field // parameters in the form. sb.append(CLEAR_HIDDEN_FIELD_FN_NAME + "_" + formClientId); + sb.append(CLEAR_HIDDEN_FIELD_FN_NAME + "_" + formClientId.replace(NamingContainer.SEPARATOR_CHAR, '_')); sb.append("('"); sb.append(formClientId); sb.append("');"); Index: src/com/sun/faces/renderkit/html_basic/FormRenderer.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/FormRenderer.java,v retrieving revision 1.83 diff -u -r1.83 FormRenderer.java FormRenderer.java 10 Mar 2005 21:39:15 -0000 1.83 +++ FormRenderer.java 15 Apr 2005 01:08:21 -0000 @@ -18,6 +18,7 @@ import javax.faces.component.UIComponent; import javax.faces.component.UIForm; +import javax.faces.component.NamingContainer; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; @@ -295,7 +296,7 @@ writer.writeAttribute(SCRIPT_TYPE, "text/javascript", null); writer.write("\n<!--"); writer.write("\nfunction "); String functionName = (CLEAR_HIDDEN_FIELD_FN_NAME + "_" + formName); + String functionName = (CLEAR_HIDDEN_FIELD_FN_NAME + "_" + formName.replace(NamingContainer.SEPARATOR_CHAR, '_')); writer.write(functionName); writer.write("(curFormName) {"); writer.write("\n var curForm = document.forms [curFormName] ;");
        Hide
        rogerk added a comment -

        Thanks for the patch. This is a good catch.
        I've verified the patch works.

        -roger

        Show
        rogerk added a comment - Thanks for the patch. This is a good catch. I've verified the patch works. -roger
        Hide
        rogerk added a comment -

        Patch has been applied.
        Again, thanks.
        Keep the reviews/fixes coming!

        -roger

        Show
        rogerk added a comment - Patch has been applied. Again, thanks. Keep the reviews/fixes coming! -roger
        Hide
        Manfred Riem added a comment -

        Closing issue out

        Show
        Manfred Riem added a comment - Closing issue out

          People

          • Assignee:
            javaserverfowner
            Reporter:
            youngm
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: