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 2012/02/27 14:27:07 UTC

svn commit: r1294146 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/ core/ xhrCore/ xhrCore/engine/

Author: werpu
Date: Mon Feb 27 13:27:07 2012
New Revision: 1294146

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

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/_util/_DomExperimental.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ExtDom.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.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/core/_EvalHandlers.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/IFrame.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=1294146&r1=1294145&r2=1294146&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 Mon Feb 27 13:27:07 2012
@@ -142,7 +142,7 @@ _MF_SINGLTN(_PFX_UTIL + "_Dom", Object, 
                             }
                             _RT.loadScriptEval(src, item.getAttribute('type'), false, "UTF-8", false);
                         }
-                        //TODO handle embedded scripts
+
                     } else {
                         // embedded script auto eval
                         var test = (!xmlData) ? item.text : _Lang.serializeChilds(item);
@@ -343,7 +343,7 @@ _MF_SINGLTN(_PFX_UTIL + "_Dom", Object, 
 
         for (var cnt = 0; cnt < evalNodes.length; cnt++) {
             if (currentRef.nextSibling) {
-                //TODO winmobile6 has problems with this strategy
+                //Winmobile 6 has problems with this strategy, but it is not really fixable
                 currentRef = parentNode.insertBefore(evalNodes[cnt], currentRef.nextSibling);
             } else {
                 currentRef = parentNode.appendChild(evalNodes[cnt]);
@@ -515,7 +515,7 @@ _MF_SINGLTN(_PFX_UTIL + "_Dom", Object, 
             var nonIEQuirks = (!this._RT.browser.isIE || this._RT.browser.isIE > 8);
             //ie8 has a special problem it still has the swallow scripts and other
             //elements bug, but it is mostly dom compliant so we have to give it a special
-            //treatment
+            //treatment, IE9 finally fixes that issue finally after 10 years
             evalNodes = (this.isDomCompliant() &&  nonIEQuirks) ?
                     this._buildNodesCompliant(markup) :
                     //ie8 or quirks mode browsers
@@ -980,7 +980,6 @@ _MF_SINGLTN(_PFX_UTIL + "_Dom", Object, 
      * fetches the window id for the current request
      * note, this is a preparation method for jsf 2.2
      *
-     * todo move this into the experimental part
      */
     getWindowId: function() {
         //implementation in the experimental part

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_DomExperimental.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_DomExperimental.js?rev=1294146&r1=1294145&r2=1294146&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_DomExperimental.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_DomExperimental.js Mon Feb 27 13:27:07 2012
@@ -1,25 +1,88 @@
 if (_MF_SINGLTN) {
     _MF_SINGLTN(_PFX_UTIL + "_DomExperimental", myfaces._impl._util._Dom, /** @lends myfaces._impl._util._Dom.prototype */ {
-        constructor_: function() {
+        constructor_:function () {
             this._callSuper("constructor_");
             myfaces._impl._util._Dom = this;
         },
 
         /**
-         * fetches the window id for the current request
-         * note, this is a preparation method for jsf 2.2
-         *
-         * todo move this into the experimental part
+         * The function allows to fetch the windowid from any arbitrary elements
+         * parent or child form.
+         * If more than one unique windowid is found then an error is thrown.
+         * @param {optional} element, searches for the windowid from any given arbitrary element
+         * a search first for embedded forms is performed and then for the parent form. If no form is found at
+         * all, or the element is not given then a search on document.forms is performed and if that
+         * does not bring any result a search within the url is performed as last fallback.
+         * @throws an error in case of having more than one unique windowIds depending on the given
+         * node element
          */
-        getWindowId: function() {
-            var href = window.location.href;
-            var windowId = "windowId";
-            var regex = new RegExp("[\\?&]" + windowId + "=([^&#\\;]*)");
-            var results = regex.exec(href);
-            return (results != null) ? results[1] : null;
+        getWindowId:function (node) {
+
+            var FORM = "form";
+
+            var fetchWindowIdFromForms = function (forms) {
+                var result_idx = {};
+                var result;
+                var foundCnt = 0;
+                for (var cnt = forms.length - 1; cnt >= 0; cnt--) {
+                    var currentForm = forms[cnt];
+                    var windowId = currentForm["javax.faces.WindowId"] && currentForm["javax.faces.WindowId"].value;
+                    if ('undefined' != typeof windowId) {
+                        if (foundCnt > 0 && 'undefined' == typeof result_idx[windowId]) throw Error("Multiple different windowIds found in document");
+                        result = windowId;
+                        result_idx[windowId] = true;
+                        foundCnt++;
+                    }
+                }
+                return result;
+            }
+
+            var getChildForms = function (currentElement) {
+
+                var targetArr = [];
+                if(!currentElement.tagName) return [];
+                else if (currentElement.tagName.toLowerCase() == FORM) {
+                    targetArr.push(currentElement);
+                    return targetArr;
+                }
+                //old recursive way, due to flakeyness of querySelectorAll
+                for (var cnt = currentElement.childNodes.length - 1; cnt >= 0; cnt--) {
+                    var currentChild = currentElement.childNodes[cnt];
+                    targetArr = targetArr.concat(getChildForms(currentChild, FORM));
+                }
+                return targetArr;
+            }
+
+            var findParentForms = function(element) {
+                while(element != null) {
+                    if(element.tagName.toLowerCase() == FORM) return [element];
+                    element = element.parentNode;
+                }
+                return document.forms;
+            }
+
+            var fetchWindowIdFromURL = function() {
+                var href = window.location.href;
+                var windowId = "windowId";
+                var regex = new RegExp("[\\?&]" + windowId + "=([^&#\\;]*)");
+                var results = regex.exec(href);
+                //initial trial over the url and a regexp
+                if (results != null) return results[1];
+                return null;
+            }
+            var forms = [];
+            if(node) {
+                var forms = getChildForms(node);
+                if(!forms || forms.length == 0) {
+                    //We walk up the parent until we hit a form or document.body
+                    forms = findParentForms(node);
+                }
+            }
+            var result = fetchWindowIdFromForms(forms);
+            return (null != result)? result:  fetchWindowIdFromURL();
         },
 
-        html5FormDetection: function(item) {
+        html5FormDetection:function (item) {
             var browser = this._RT.browser;
             //ie shortcut, not really needed but speeds things up
             if (browser.isIEMobile && browser.isIEMobile <= 8) {
@@ -29,18 +92,17 @@ if (_MF_SINGLTN) {
             return (elemForm) ? this.byId(elemForm) : null;
         },
 
-        //TODO move this into the extended features part
-        isMultipartCandidate: function(executes) {
+        isMultipartCandidate:function (executes) {
             if (this._Lang.isString(executes)) {
                 executes = this._Lang.strToArray(executes, /\s+/);
             }
 
             for (var executable in executes) {
-                if(!executes.hasOwnProperty(executable)) continue;
+                if (!executes.hasOwnProperty(executable)) continue;
                 var element = this.byId(executes[executable]);
                 var inputs = this.findByTagName(element, "input", true);
                 for (var key in inputs) {
-                    if(!inputs.hasOwnProperty(key)) continue;
+                    if (!inputs.hasOwnProperty(key)) continue;
                     if (this.getAttribute(inputs[key], "type") == "file") return true;
                 }
             }

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ExtDom.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ExtDom.js?rev=1294146&r1=1294145&r2=1294146&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ExtDom.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ExtDom.js Mon Feb 27 13:27:07 2012
@@ -61,7 +61,8 @@ _MF_SINGLTN && _MF_SINGLTN(_PFX_UTIL + "
 
             //html5 getElementsByClassname
 
-            //TODO implement this
+            //TODO implement this, there is a better way to check for styleclasses
+            //check the richfaces code for that one
             /*if (fragment.getElementsByClassName && deepScan) {
              return fragment.getElementsByClassName(styleClass);
              }

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js?rev=1294146&r1=1294145&r2=1294146&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js Mon Feb 27 13:27:07 2012
@@ -452,7 +452,6 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object,
         return buffer.join("");
     },
     isXMLParseError:function (xmlContent) {
-        //TODO determine the ie specific part here
         //no xml content
         if (xmlContent == null) return true;
         var findParseError = function (node) {
@@ -617,8 +616,6 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object,
      * in the long run we probably can switch over
      * or make a code split between legacy and new
      *
-     * TODO find a way to map this mechanism to the standard
-     * props mechanism modern browsers have
      *
      * @param obj
      * @param name

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=1294146&r1=1294145&r2=1294146&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 Mon Feb 27 13:27:07 2012
@@ -129,10 +129,6 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
      * @param {|Object|} options  map of options being pushed into the ajax cycle
      *
      *
-     * TODO refactoring, the passthrgh handling is only for dragging in request parameters
-     * we should rewrite this part
-     *
-     *
      * a) transformArguments out of the function
      * b) passThrough handling with a map copy with a filter map block map
      */
@@ -718,11 +714,8 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
             //this is a valid approach
             if (this._threshold == "ERROR") {
                 var mfInternal = exception._mfInternal || {};
-                //TODO clean the name mess here
-                var finalMsg = [];
-
-
 
+                var finalMsg = [];
                 finalMsg.push(exception.message);
                 this.sendError(request, context,
                         mfInternal.title || this.CLIENT_ERROR, mfInternal.name || exception.name, finalMsg.join("\n"), mfInternal.caller, mfInternal.callFunc);

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_EvalHandlers.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_EvalHandlers.js?rev=1294146&r1=1294145&r2=1294146&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_EvalHandlers.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_EvalHandlers.js Mon Feb 27 13:27:07 2012
@@ -1,9 +1,22 @@
 /**
  * @namespace
  * @name window
- * @description supplimental window methods.
+ * @description Eval routines, depending on the browser.
+ * <p/>
+ * The problem solved in this class is the problem on how to perform
+ * a global eval on multiple browsers. Some browsers auto eval themselves
+ * they do not need to be called
+ * <li>Some work with a window.eval.call(window,... </li>
+ * <li>Others use simply execScript <li>
+ * <li>Some others work only with the head appendix method
+ * head.appendChild(&lt;script...., head.removeChild(&lt;script </li>
+ * <p/>
+ * Note: The code here already is precompressed because the compressor
+ * fails on it, the deficits in readability will be covered by more comments
+ *
  */
 
+
 if (!window.myfaces) {
     /**
      * @namespace
@@ -51,6 +64,10 @@ if (!myfaces._impl.core._EvalHandlers) {
          * evals a script globally using exec script (ie6 fallback)
          * @param {String} code the code which has to be evaluated
          * @borrows myfaces._impl.core._Runtime as _T
+         *
+         * TODO eval if we cannot replace this method with the head appendix
+         * method which is faster for ie this also would reduce our code
+         * by a few bytes
          */
         _T._evalExecScript = function(code) {
             //execScript definitely only for IE otherwise we might have a custom
@@ -74,7 +91,7 @@ if (!myfaces._impl.core._EvalHandlers) {
          * @param {String} code the code part to be evaled
          * @borrows myfaces._impl.core._Runtime as _T
          */
-        _T._evalBBOld = function(code) {
+        _T._evalHeadAppendix = function(code) {
             //_l == location
             var _l = document.getElementsByTagName("head")[0] || document.documentElement;
             //_p == placeHolder
@@ -95,7 +112,8 @@ if (!myfaces._impl.core._EvalHandlers) {
             //fix which works in a cross browser way
             //we used to scope an anonymous function
             //but I think this is better
-            //the reason is firefox applies a wrong scope
+            //the reason is some Firefox versions
+            // apply a wrong scope
             //if we call eval by not scoping
             //_U == "undefined"
             var _U = "undefined";
@@ -124,12 +142,20 @@ if (!myfaces._impl.core._EvalHandlers) {
             var _e = "_evalType";
             var _w = window;
             var _b = myfaces._impl.core._Runtime.browser;
+            //central routine to determine the eval method
             if (!_T[_e]) {
+                //execScript supported
                 _T[_e] = _w.execScript ? "_evalExecScript" : null;
+
+                //in case of no support we go to the standard global eval  window.eval.call(window,
+                // with Firefox fixes for scoping
                 _T[_e] = _T[_e] ||(( _w.eval && (!_b.isBlackBerry ||_b.isBlackBerry >= 6)) ? "_standardGlobalEval" : null);
-                _T[_e] = _T[_e] ||((_w.eval ) ? "_evalBBOld" : null);
+
+                //this one routes into the hed appendix method
+                _T[_e] = _T[_e] ||((_w.eval ) ? "_evalHeadAppendix" : null);
             }
             if (_T[_e]) {
+                //we now execute the eval method
                 return _T[_T[_e]](c);
             }
             //we probably have covered all browsers, but this is a safety net which might be triggered

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=1294146&r1=1294145&r2=1294146&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 Mon Feb 27 13:27:07 2012
@@ -209,6 +209,7 @@ _MF_SINGLTN(_PFX_XHR + "_AjaxResponse", 
             this._Dom.setAttribute(viewStateField, "value", mfInternal.appliedViewState);
         } else if (!viewStateField) {
             var element = this._Dom.getDummyPlaceHolder();
+            //spec error, two elements with the same id should not be there, TODO recheck the space if the name does not suffice alone
             element.innerHTML = ["<input type='hidden'", "id='", this.P_VIEWSTATE ,"' name='", this.P_VIEWSTATE ,"' value='" , mfInternal.appliedViewState , "' />"].join("");
             //now we go to proper dom handling after having to deal with another ie screwup
             try {
@@ -328,7 +329,7 @@ _MF_SINGLTN(_PFX_XHR + "_AjaxResponse", 
     ,
 
     /**
-     * First substep process a pending update tag
+     * First sub-step process a pending update tag
      *
      * @param request the xhr request object
      * @param context the context map

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/IFrame.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/IFrame.js?rev=1294146&r1=1294145&r2=1294146&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/IFrame.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/IFrame.js Mon Feb 27 13:27:07 2012
@@ -101,10 +101,11 @@ _MF_CLS(_PFX_XHR+"engine.IFrame", myface
                 this.onloadstart(myevt);
                 this.onprogress(myevt);
 
-                var oldTarget = formData.form.target;
-                var oldMethod = formData.form.method;
-                var oldAction = formData.form.action;
-                var formDataForm = formData.form;
+                var formDataForm = formData.form,
+                    oldTarget   = formDataForm.target,
+                    oldMethod   = formDataForm.method,
+                    oldAction   = formDataForm.action;
+
                 
                 try {
                     //_t._initAjaxParams();
@@ -112,18 +113,18 @@ _MF_CLS(_PFX_XHR+"engine.IFrame", myface
                         formData.append(key, this._requestHeader[key]);
                     }
 
-                    formData.form.target = this._frame.name;
-                    formData.form.method = this.method;
+                    formDataForm.target = this._frame.name;
+                    formDataForm.method = this.method;
                     if (this.url) {
-                        formData.form.action = this.url;
+                        formDataForm.action = this.url;
                     }
                     this.readyState = this._XHRConst.READY_STATE_LOADING;
                     this.onreadystatechange(myevt);
-                    formData.form.submit();
+                    formDataForm.submit();
                 } finally {
-                    formData.form.action = oldAction;
-                    formData.form.target = oldTarget;
-                    formData.form.method = oldMethod;
+                    formDataForm.action = oldAction;
+                    formDataForm.target = oldTarget;
+                    formDataForm.method = oldMethod;
 
                     formData._finalize();
                 }