javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-2749

Attribute updates targeting the event handlers fail to work when 'this' or 'return' keywords are used

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.13
    • Fix Version/s: 2.1.25, 2.2.2
    • Component/s: ajax
    • Labels:
      None
    • Environment:

      Internet Explorer 7 or 8

      Description

      When on* attributes are updated in IE with event handler code that contains the 'this' variable the browser will fail to reference the targeted element (as expected). When window.execScript function is used to evaluate scripts the 'this' variable references the window object.

      Also when 'return' statement is used in the event handler code IE will throw the following error:

      Line: 1
      Char: 217
      Error: 'return' statement outside of function
      Code: 0
      

      Using 'return' statements in a event handler is a valid way of enabling or disabling the execution of default action in the browser.

        Activity

        Hide
        mirceatoma added a comment - - edited

        The solution that I found to work well in Internet Explorer was to create an element with the new event handler code and then copy the event handler function to the target element. The function then will reference correctly the 'this' keyword. Also since 'return' statement is found in the body of the function the browser will not complain anymore.
        Here's the patch:

        Index: jsf-api/src/main/resources/jsf.js
        ===================================================================
        --- jsf-api/src/main/resources/jsf.js	(revision 11649)
        +++ jsf-api/src/main/resources/jsf.js	(working copy)
        @@ -1247,12 +1247,13 @@
                             } else if (name === 'style') {
                                 target.style.setAttribute('cssText', value, 0);
                             } else if (name.substring(0, 2) === 'on') {
        -                        var fn = function(value) {
        -                            return function() {
        -                                window.execScript(value);
        -                            };
        -                        }(value);
        -                        target.setAttribute(name, fn, 0);
        +                        var c = document.body.appendChild(document.createElement('span'));
        +                        try {
        +                            c.innerHTML = '<span ' + name + '="' + value + '"/>';
        +                            target[name] = c.firstChild[name];
        +                        } finally {
        +                            document.body.removeChild(c);
        +                        }
                             } else if (name === 'dir') {
                                 if (jsf.getProjectStage() == 'Development') {
                                     throw new Error("Cannot set 'dir' attribute in IE");
        
        Show
        mirceatoma added a comment - - edited The solution that I found to work well in Internet Explorer was to create an element with the new event handler code and then copy the event handler function to the target element. The function then will reference correctly the 'this' keyword. Also since 'return' statement is found in the body of the function the browser will not complain anymore. Here's the patch: Index: jsf-api/src/main/resources/jsf.js =================================================================== --- jsf-api/src/main/resources/jsf.js (revision 11649) +++ jsf-api/src/main/resources/jsf.js (working copy) @@ -1247,12 +1247,13 @@ } else if (name === 'style') { target.style.setAttribute('cssText', value, 0); } else if (name.substring(0, 2) === 'on') { - var fn = function(value) { - return function() { - window.execScript(value); - }; - }(value); - target.setAttribute(name, fn, 0); + var c = document.body.appendChild(document.createElement('span')); + try { + c.innerHTML = '<span ' + name + '= "' + value + '" />'; + target[name] = c.firstChild[name]; + } finally { + document.body.removeChild(c); + } } else if (name === 'dir') { if (jsf.getProjectStage() == 'Development') { throw new Error( "Cannot set 'dir' attribute in IE" );
        Hide
        mirceatoma added a comment -

        The originating issue is http://jira.icesoft.org/browse/ICE-8430 .

        Show
        mirceatoma added a comment - The originating issue is http://jira.icesoft.org/browse/ICE-8430 .
        Hide
        Manfred Riem added a comment -

        Can you please tell us which version is affected?

        Show
        Manfred Riem added a comment - Can you please tell us which version is affected?
        Hide
        mirceatoma added a comment -

        Mojarra 2.1.13.

        Sorry, for the delayed reply.

        Show
        mirceatoma added a comment - Mojarra 2.1.13. Sorry, for the delayed reply.
        Hide
        rogerk added a comment -

        Any chance you can provide a small reproducing test case?

        Show
        rogerk added a comment - Any chance you can provide a small reproducing test case?
        Hide
        rogerk added a comment -

        Changes.

        Show
        rogerk added a comment - Changes.
        Hide
        rogerk added a comment -

        Committed to MOJARRA_2_2X_ROLLING branch:
        Sending jsf-api/src/main/resources/jsf.js
        Sending test/agnostic/ajax/src/main/java/com/sun/faces/test/agnostic/ajax/UpdateBean.java
        Adding test/agnostic/ajax/src/main/webapp/attributeNameIsOn.xhtml
        Adding test/agnostic/ajax/src/test/java/com/sun/faces/test/agnostic/ajax/Issue2749IT.java
        Transmitting file data ....
        Committed revision 12093.

        Committed to MOJARRA_2_1X_ROLLING branch:

        Sending jsf-api/src/main/resources/jsf.js
        Sending test/agnostic/ajax/src/main/java/com/sun/faces/test/agnostic/ajax/UpdateBean.java
        Adding test/agnostic/ajax/src/test/java/com/sun/faces/test/agnostic/ajax/Issue2749IT.java
        Transmitting file data ...
        Committed revision 12091.

        Adding test/agnostic/ajax/src/main/webapp/attributeNameIsOn.xhtml
        Transmitting file data .
        Committed revision 12092.

        Show
        rogerk added a comment - Committed to MOJARRA_2_2X_ROLLING branch: Sending jsf-api/src/main/resources/jsf.js Sending test/agnostic/ajax/src/main/java/com/sun/faces/test/agnostic/ajax/UpdateBean.java Adding test/agnostic/ajax/src/main/webapp/attributeNameIsOn.xhtml Adding test/agnostic/ajax/src/test/java/com/sun/faces/test/agnostic/ajax/Issue2749IT.java Transmitting file data .... Committed revision 12093. Committed to MOJARRA_2_1X_ROLLING branch: Sending jsf-api/src/main/resources/jsf.js Sending test/agnostic/ajax/src/main/java/com/sun/faces/test/agnostic/ajax/UpdateBean.java Adding test/agnostic/ajax/src/test/java/com/sun/faces/test/agnostic/ajax/Issue2749IT.java Transmitting file data ... Committed revision 12091. Adding test/agnostic/ajax/src/main/webapp/attributeNameIsOn.xhtml Transmitting file data . Committed revision 12092.
        Hide
        rogerk added a comment -

        Committed.

        Show
        rogerk added a comment - Committed.

          People

          • Assignee:
            rogerk
            Reporter:
            mirceatoma
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: