<< Back to previous view

[JAVASERVERFACES-2749] Attribute updates targeting the event handlers fail to work when 'this' or 'return' keywords are used Created: 22/Feb/13  Updated: 12/Jul/13  Resolved: 12/Jul/13

Status: Closed
Project: javaserverfaces
Component/s: ajax
Affects Version/s: 2.1.13
Fix Version/s: 2.1.25, 2.2.2

Type: Bug Priority: Major
Reporter: mirceatoma Assignee: rogerk
Resolution: Fixed Votes: 1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Internet Explorer 7 or 8


File Attachments: Text File changebundle-2749.txt    
Tags:
Participants: Manfred Riem, mirceatoma and rogerk

 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.



 Comments   
Comment by mirceatoma [ 22/Feb/13 07:44 PM ]

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");
Comment by mirceatoma [ 22/Feb/13 07:49 PM ]

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

Comment by Manfred Riem [ 26/Mar/13 01:03 PM ]

Can you please tell us which version is affected?

Comment by mirceatoma [ 26/Mar/13 01:09 PM ]

Mojarra 2.1.13.

Sorry, for the delayed reply.

Comment by rogerk [ 17/Jun/13 07:23 PM ]

Any chance you can provide a small reproducing test case?

Comment by rogerk [ 11/Jul/13 09:19 PM ]

Changes.

Comment by rogerk [ 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.

Comment by rogerk [ 12/Jul/13 01:04 AM ]

Committed.

Generated at Fri Apr 25 03:41:37 UTC 2014 using JIRA 4.0.2#472.