You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/08/18 19:58:40 UTC

svn commit: r986825 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/_Dom.js core/Impl.js xhrCore/_AjaxRequest.js xhrCore/_AjaxResponse.js

Author: werpu
Date: Wed Aug 18 17:58:40 2010
New Revision: 986825

URL: http://svn.apache.org/viewvc?rev=986825&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2876

body replacement also now working, but the browser engine is flakey, unbelievable...
even if it works I cannot recommend to use it except for small stuff.

Modified:
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js?rev=986825&r1=986824&r2=986825&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js Wed Aug 18 17:58:40 2010
@@ -75,7 +75,7 @@ myfaces._impl.core._Runtime.singletonExt
         if (b.isIE <= 6 && b.isIEMobile) {
             //winmobile hates add onLoad, and checks on the construct
             //it does not eval scripts anyway
-            myfaces.config = myfaces.config||{};
+            myfaces.config = myfaces.config || {};
             myfaces.config._autoeval = false;
             return;
         }
@@ -895,11 +895,14 @@ myfaces._impl.core._Runtime.singletonExt
 
             //html 5 allows finally the detachement of elements
             //by introducing a form attribute
-            var elemForm = this.getAttribute(elem, "form");
+
+            var elemForm = this.html5FormDetection(elem);
             if (elemForm) {
-                return this.byId(elemForm);
+                return elemForm;
             }
 
+
+
             //element of type form then we are already
             //at form level for the issuing element
             //https://issues.apache.org/jira/browse/MYFACES-2793
@@ -925,9 +928,9 @@ myfaces._impl.core._Runtime.singletonExt
         if (id && '' != id) {
             //we have to assert that the element passed down is detached
             var domElement = this.byId(id);
-            var elemForm = this.getAttribute(domElement, "form");
+            var elemForm = this.html5FormDetection(domElement);
             if (elemForm) {
-                return this.byId(elemForm);
+                return elemForm;
             }
 
             if (domElement) {
@@ -960,6 +963,17 @@ myfaces._impl.core._Runtime.singletonExt
     }
     ,
 
+    html5FormDetection: function(item) {
+        if(this._RT.browser.isIEMobile && this._RT.browser.isIEMobile <= 7) {
+            return null;    
+        }
+        var elemForm = this.getAttribute(item, "form");
+        if (elemForm) {
+            return this.byId(elemForm);
+        }
+        return null;
+    },
+
     /**
      * gets a parent of an item with a given tagname
      * @param {Node} item - child element

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js?rev=986825&r1=986824&r2=986825&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js Wed Aug 18 17:58:40 2010
@@ -118,7 +118,6 @@ myfaces._impl.core._Runtime.singletonExt
      */
     request : function(elem, event, options) {
 
-
         /*namespace remap for our local function context we mix the entire function namespace into
          *a local function variable so that we do not have to write the entire namespace
          *all the time
@@ -162,7 +161,6 @@ myfaces._impl.core._Runtime.singletonExt
          */
         var passThrgh = _Lang.mixMaps({}, options, true);
 
-
         /*additional passthrough cleanup*/
         /*ie6 supportive code to prevent browser leaks*/
         passThrgh.onevent = null;
@@ -276,7 +274,6 @@ myfaces._impl.core._Runtime.singletonExt
             _this = null;
             transformList = null;
         }
-
         var getConfig = myfaces._impl.core._Runtime.getLocalOrGlobalConfig;
 
         /**

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js?rev=986825&r1=986824&r2=986825&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js Wed Aug 18 17:58:40 2010
@@ -40,7 +40,7 @@ myfaces._impl.core._Runtime.extendClass(
      *
      */
     constructor_: function(arguments) {
-        
+
 
         try {
             this._callSuper("constructor", arguments);
@@ -137,22 +137,22 @@ myfaces._impl.core._Runtime.extendClass(
                 //we unify the api, there must be always a request passed to the external function
                 //and always a context, no matter what
                     this._Lang.hitch(this,
-                            function() {
-                                //the hitch has to be done due to the setTimeout refocusing the scope of this
-                                //to window
-                                try {
-                                    _req.onreadystatechange = function() {
-                                    };
-
-                                    //to avoid malformed whatever, we have
-                                    //the timeout covered already on the _onTimeout function
-                                    _req.abort();
-                                    this._onTimeout(_req, _context);
-                                } catch (e) {
-                                    alert(e);
-                                } finally {
-                                }
-                            })
+                                    function() {
+                                        //the hitch has to be done due to the setTimeout refocusing the scope of this
+                                        //to window
+                                        try {
+                                            _req.onreadystatechange = function() {
+                                            };
+
+                                            //to avoid malformed whatever, we have
+                                            //the timeout covered already on the _onTimeout function
+                                            _req.abort();
+                                            this._onTimeout(_req, _context);
+                                        } catch (e) {
+                                            alert(e);
+                                        } finally {
+                                        }
+                                    })
                     , this._timeout);
         }
     },
@@ -181,7 +181,7 @@ myfaces._impl.core._Runtime.extendClass(
                 }
             }
         } catch (e) {
-            if(this._onException)
+            if (this._onException)
                 this._onException(this._xhr, this._context, "myfaces._impl.xhrCore._AjaxRequest", "callback", e);
             else
                 alert(e.toString());
@@ -190,7 +190,7 @@ myfaces._impl.core._Runtime.extendClass(
             this._Lang.clearExceptionProcessed();
 
             //this._context.source;
-            if(this._xhr.readyState == this._READY_STATE_DONE) {
+            if (this._xhr.readyState == this._READY_STATE_DONE) {
                 this._callSuper("_finalize");
             }
 

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=986825&r1=986824&r2=986825&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Wed Aug 18 17:58:40 2010
@@ -161,8 +161,8 @@ myfaces._impl.core._Runtime.extendClass(
         //if we set our no portlet env we safely can update all forms with
         //the new viewstate
         if (this._RT.getLocalOrGlobalConfig(context, "no_portlet_env", false)) {
-            for(var cnt = document.forms.length-1; cnt >= 0; cnt --) {
-                 this._setVSTForm(document.forms[cnt]);
+            for (var cnt = document.forms.length - 1; cnt >= 0; cnt --) {
+                this._setVSTForm(document.forms[cnt]);
             }
             return;
         }
@@ -268,6 +268,7 @@ myfaces._impl.core._Runtime.extendClass(
         //the realignment must happen post change processing
         for (var i = 0; i < changes.length; i++) {
             switch (changes[i].tagName) {
+
                 case this.CMD_UPDATE:
                     if (!this.processUpdate(request, context, changes[i])) {
                         return false;
@@ -440,28 +441,33 @@ myfaces._impl.core._Runtime.extendClass(
      * @param {Node} parsedData (optional) preparsed XML representation data of the current document
      */
     _replaceBody : function(request, context, newData /*varargs*/) {
-        var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
 
+        var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
         var oldBody = document.getElementsByTagName("body")[0];
-        var newBody = document.createElement("body");
+
         var placeHolder = document.createElement("div");
+
         placeHolder.id = "myfaces_bodyplaceholder";
+
         var bodyParent = oldBody.parentNode;
-        bodyParent.replaceChild(newBody, oldBody);
-        //TODO .. ie gcing
 
-        newBody.appendChild(placeHolder);
 
-        //the contextualFragment trick does not work on the body tag instead we have to generate a manual body
-        //element and then add a child which then is the replacement holder for our fragment!
+        if (!this._RT.browser.isIEMobile || this._RT.browser.isIEMobile >= 7) {
+            //if possible we replace the entire body to get all the old attributes cleaned up
+            //which works on all new browsers
+            var newBody = document.createElement("body");
+            bodyParent.replaceChild(newBody, oldBody);
+        } else {
+            //now to the problematic engines
+            oldBody.innerHTML = "";
+            //we just clean up the old body
+            var newBody = oldBody;
+        }
+
+        newBody.appendChild(placeHolder);
 
-        //Note, we also could offload this to the browser,
-        //but for now our parser seems to be faster than the browser offloading method
-        //and also does not interfere on security level
-        //the browser offloading methods would be first to use the xml parsing
-        //and if that fails revert to a hidden iframe
-        //var bodyData = parser.parse(newData, "body");
         var bodyData = null;
+
         var doc = (arguments.length > 3) ? arguments[3] : this._Lang.parseXML(newData);
         if (this._Lang.isXMLParseError(doc)) {
             doc = this._Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]\/\/-->/g, "//-->"));
@@ -469,20 +475,24 @@ myfaces._impl.core._Runtime.extendClass(
 
         if (this._Lang.isXMLParseError(doc)) {
             //the standard xml parser failed we retry with the stripper
+
             var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
             bodyData = parser.parse(newData, "body");
         } else {
             //parser worked we go on
             var newBodyData = doc.getElementsByTagName("body")[0];
             bodyData = this._Lang.serializeChilds(newBodyData);
-            for (var cnt = 0; cnt < newBodyData.attributes.length; cnt++) {
-                var value = newBodyData.attributes[cnt].value;
-                if (value)
-                    this._Dom.setAttribute(newBody, newBodyData.attributes[cnt].name, value);
+
+            if (!this._RT.browser.isIEMobile || this._RT.browser.isIEMobile >= 7) {
+                //TODO check what is failing there
+                for (var cnt = 0; cnt < newBodyData.attributes.length; cnt++) {
+                    var value = newBodyData.attributes[cnt].value;
+                    if (value)
+                        this._Dom.setAttribute(newBody, newBodyData.attributes[cnt].name, value);
+                }
             }
         }
 
-
         var returnedElement = this.replaceHtmlItem(request, context, placeHolder, bodyData);
         if (returnedElement) {
             this._pushOperationResult(returnedElement);
@@ -589,7 +599,7 @@ myfaces._impl.core._Runtime.extendClass(
 
             nodeHolder = document.createElement("div");
             parentNode = afterNode.parentNode;
-            
+
             //TODO nextsibling not working in ieMobile 6.1 we have to change the method
             //of accessing it to something else
             parentNode.insertBefore(nodeHolder, afterNode.nextSibling);