Issue Details (XML | Word | Printable)

Key: JAVASERVERFACES-2749
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: rogerk
Reporter: mirceatoma
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
javaserverfaces

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

Created: 22/Feb/13 07:38 PM   Updated: 12/Jul/13 01:04 AM   Resolved: 12/Jul/13 01:04 AM
Component/s: ajax
Affects Version/s: 2.1.13
Fix Version/s: 2.1.25, 2.2.2

Time Tracking:
Not Specified

File Attachments: 1. Text File changebundle-2749.txt (11 kB) 11/Jul/13 09:19 PM - rogerk

Environment:

Internet Explorer 7 or 8


Tags:
Participants: Manfred Riem, mirceatoma and rogerk


 Description  « Hide

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.



mirceatoma added a comment - 22/Feb/13 07:44 PM - 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");

mirceatoma added a comment - 22/Feb/13 07:49 PM

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


Manfred Riem added a comment - 26/Mar/13 01:03 PM

Can you please tell us which version is affected?


mirceatoma added a comment - 26/Mar/13 01:09 PM

Mojarra 2.1.13.

Sorry, for the delayed reply.


rogerk added a comment - 17/Jun/13 07:23 PM

Any chance you can provide a small reproducing test case?


rogerk added a comment - 11/Jul/13 09:19 PM

Changes.


rogerk added a comment - 12/Jul/13 01:04 AM

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.


rogerk added a comment - 12/Jul/13 01:04 AM

Committed.