myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r960856 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/ core/ xhrCore/
Date Tue, 06 Jul 2010 09:40:51 GMT
Author: werpu
Date: Tue Jul  6 09:40:51 2010
New Revision: 960856

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

Fixed up the 2.1 functionality which we had embedded,
queue control
pps
timeout
delay

all working now as expected

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/_Queue.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/_Runtime.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/_AjaxRequestQueue.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.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=960856&r1=960855&r2=960856&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
Tue Jul  6 09:40:51 2010
@@ -391,6 +391,52 @@ myfaces._impl.core._Runtime.singletonExt
         return null;
     },
 
+
+    /**
+     * optimized search for an array of tag names
+     *
+     * @param fragment the fragment which should be searched for
+     * @param tagNames an map indx of tag names which have to be found
+     * @param deepScan if set to true a deep scan is performed otherwise a shallow scan
+     */
+    findByTagNames: function(fragment, tagNames, deepScan) {
+        var _Lang = myfaces._impl._util._Lang;
+
+        //shortcut for single components
+        if(!deepScan && tagNames[fragment.tagName.toLowerCase()]) {
+            return fragment;
+        }
+
+        //shortcut elementsByTagName
+        if (deepScan && _Lang.exists(fragment, "getElementsByTagName")) {
+            var retArr = [];
+            for (var key in tagNames) {
+                var foundElems = this.findByTagName(fragment, key, deepScan);
+                if (foundElems) {
+                    retArr = retArr.concat(foundElems);
+                }
+            }
+            return retArr;
+        } else if (deepScan) {
+            //no node type with child tags we can handle that without node type checking
+            return null;
+        }
+
+
+        //now the filter function checks case insensitively for the tag names needed
+        var filter = function(node) {
+            return node.tagName && tagNames[node.tagName.toLowerCase()];
+        };
+
+        //now we run an optimized find all on it
+        try {
+            return this.findAll(fragment, filter, deepScan);
+        } finally {
+            //the usual IE6 is broken, fix code
+            filter = null;
+        }
+    },
+
     /**
      * determines the number of nodes according to their tagType
      *
@@ -414,9 +460,9 @@ myfaces._impl.core._Runtime.singletonExt
         //via namespace array checking is safe
         if (deepScan && _Lang.exists(fragment, "getElementsByTagName")) {
             var ret = _Lang.objToArray(fragment.getElementsByTagName(tagName));
-            if(fragment.tagName && fragment.tagName.toLowerCase() == tagName.toLocaleLowerCase())
ret.unshift(fragment);
+            if (fragment.tagName && fragment.tagName.toLowerCase() == tagName.toLowerCase())
ret.unshift(fragment);
             return ret;
-        } else if(deepScan) {
+        } else if (deepScan) {
             //no node type with child tags we can handle that without node type checking
             return null;
         }
@@ -449,12 +495,11 @@ myfaces._impl.core._Runtime.singletonExt
             //elements byName is the fastest
             if (deepScan && _Lang.exists(fragment, "getElementsByName")) {
                 var ret = _Lang.objToArray(fragment.getElementsByName(name));
-                if(fragment.name == name) ret.unshift(fragment);
+                if (fragment.name == name) ret.unshift(fragment);
                 return ret;
 
             }
 
-
             if (deepScan && _Lang.exists(fragment, "querySelectorAll")) {
                 try {
                     var newName = name;
@@ -508,13 +553,13 @@ myfaces._impl.core._Runtime.singletonExt
 
             //TODO implement this
             /*if (fragment.getElementsByClassName && deepScan) {
-                return fragment.getElementsByClassName(styleClass);
-            }
+             return fragment.getElementsByClassName(styleClass);
+             }
 
-            //html5 speed optimization for browsers which do not ,
-            //have the getElementsByClassName implemented
-            //but only for deep scan and normal parent nodes
-            else */
+             //html5 speed optimization for browsers which do not ,
+             //have the getElementsByClassName implemented
+             //but only for deep scan and normal parent nodes
+             else */
             if (_Lang.exists(fragment, "querySelectorAll") && deepScan) {
                 try {
                     var result = fragment.querySelectorAll("." + styleClass.replace(/\./g,
"\\."));

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js?rev=960856&r1=960855&r2=960856&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
(original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
Tue Jul  6 09:40:51 2010
@@ -54,11 +54,13 @@ myfaces._impl.core._Runtime.extendClass(
         this._q.push(element);
         //qeuesize is bigger than the limit we drop one element so that we are
         //back in line
+
         this._readjust();
     },
 
     _readjust: function() {
-        while (this._size > -1 && this.length() > this._size) {
+        while (null != this._size && 'undefined' != typeof this._size &&
+                this._size > -1 && this.length() > this._size) {
             this.dequeue();
         }
     },

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=960856&r1=960855&r2=960856&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
Tue Jul  6 09:40:51 2010
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
-*/
+ */
 
 /** @namespace myfaces._impl.core.Impl*/
 /** @namespace myfaces._impl._util._ListenerQueue */
@@ -65,6 +65,7 @@ myfaces._impl.core._Runtime.singletonExt
     MALFORMEDXML : "malformedXML",
     SERVER_ERROR : "serverError",
     CLIENT_ERROR : "clientError",
+    TIMEOUT_EVENT: "timeout",
 
 
 
@@ -124,7 +125,7 @@ myfaces._impl.core._Runtime.singletonExt
          * the entire mapping between the functions is stateless
          */
         //null definitely means no event passed down so we skip the ie specific checks
-        if('undefined' == typeof event) {
+        if ('undefined' == typeof event) {
             event = window.event || null;
         }
 
@@ -331,6 +332,7 @@ myfaces._impl.core._Runtime.singletonExt
      * sends an event
      */
     sendEvent : function sendEvent(/*Object*/request, /*Object*/ context, /*event name*/
name) {
+        var _Lang = myfaces._impl._util._Lang;
         var eventData = {};
         eventData.type = this.EVENT;
 
@@ -340,9 +342,18 @@ myfaces._impl.core._Runtime.singletonExt
         if (name !== this.BEGIN) {
 
             try {
-                eventData.responseCode = request.status;
-                eventData.responseText = request.responseText;
-                eventData.responseXML = request.responseXML;
+                //we bypass a problem with ie here, ie throws an exception if no status is
given on the xhr object instead of just passing a value
+                var getValue = function(value, key) {
+                    try {
+                        return value[key]
+                    } catch (e) {
+                        return "unkown";
+                    }
+                };
+
+                eventData.responseCode = getValue (request, "status");
+                eventData.responseText = getValue (request, "responseText");
+                eventData.responseXML = getValue (request, "responseXML");
 
             } catch (e) {
                 var impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js?rev=960856&r1=960855&r2=960856&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
(original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
Tue Jul  6 09:40:51 2010
@@ -220,29 +220,34 @@ if (!myfaces._impl.core._Runtime) {
             if (!subNms) {
                 return true;
             }
+            try {
+                //special condition subnamespace exists as full blown key with . instead
of function map
+                if ('undefined' != typeof root[subNms]) {
+                    return true;
+                }
 
-            //special condition subnamespace exists as full blown key with . instead of function
map
-            if ('undefined' != typeof root[subNms]) {
-                return true;
-            }
+                //crossported from the dojo toolkit
+                // summary: determine if an object supports a given method
+                // description: useful for longer api chains where you have to test each
object in the chain
+                var p = subNms.split(".");
+                var len = p.length;
+                for (var i = 0; i < len; i++) {
+                    //the original dojo code here was false because
+                    //they were testing against ! which bombs out on exists
+                    //which has a value set to false
+                    // (TODO send in a bugreport to the Dojo people)
+
+                    if ('undefined' == typeof root[p[i]]) {
+                        return false;
+                    } // Boolean
+                    root = root[p[i]];
+                }
+                return true; // Boolean
 
-            //crossported from the dojo toolkit
-            // summary: determine if an object supports a given method
-            // description: useful for longer api chains where you have to test each object
in the chain
-            var p = subNms.split(".");
-            var len = p.length;
-            for (var i = 0; i < len; i++) {
-                //the original dojo code here was false because
-                //they were testing against ! which bombs out on exists
-                //which has a value set to false
-                // (TODO send in a bugreport to the Dojo people)
-
-                if ('undefined' == typeof root[p[i]]) {
-                    return false;
-                } // Boolean
-                root = root[p[i]];
+            } catch (e) {
+                //ie (again) has a special handling for some object attributes here which
automatically throw an unspecified error if not existent
+                return false;
             }
-            return true; // Boolean
         };
 
         /**

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=960856&r1=960855&r2=960856&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
Tue Jul  6 09:40:51 2010
@@ -12,17 +12,13 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
-*/
+ */
 
 /**
  * An implementation of an xhr request object
  * with partial page submit functionality, and jsf
  * ppr request and timeout handling capabilities
  *
- * TODO there is still some jsf related logic in here
- * which has to be moved one level up in the call chain,
- * to get a clear separation of concerns
- *
  * Author: Ganesh Jung (latest modification by $Author: ganeshpuri $)
  * Version: $Revision: 1.4 $ $Date: 2009/05/31 09:16:44 $
  */
@@ -44,7 +40,7 @@ myfaces._impl.core._Runtime.extendClass(
     _exception: null,
     _timeout: null,
     _delay:null,
-
+    _queueSize:-1,
 
     _partialIdsArray : null,
     _ajaxType: "POST",
@@ -61,11 +57,12 @@ myfaces._impl.core._Runtime.extendClass(
     _onError: null,
     _onException: null,
     _onWarning: null,
+    _onTimeout:null,
 
     /*response object which is exposed to the queue*/
     _response: null,
 
-
+    _timeoutId: null,
     /*
      * constants used internally 
      */
@@ -110,46 +107,75 @@ myfaces._impl.core._Runtime.extendClass(
      * Sends an Ajax request
      */
     send : function() {
-        var _Lang = myfaces._impl._util._Lang;
         try {
-
-            this._xhr = myfaces._impl.core._Runtime.getXHRObject();
-
-            this._xhr.open(this._ajaxType, this._sourceForm.action, true);
-
-            var contentType = this._contentType;
-            if (this._encoding) {
-                contentType = contentType + "; charset:" + this._encoding;
-            }
-
-            this._xhr.setRequestHeader(this._CONTENT_TYPE, this._contentType);
-            this._xhr.setRequestHeader(this._HEAD_FACES_REQ, this._VAL_AJAX);
-
-            this._xhr.onreadystatechange = _Lang.hitch(this, this.callback);
-            var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
-            _Impl.sendEvent(this._xhr, this._context, myfaces._impl.core.Impl.BEGIN);
-            this._xhr.send(this._requestParameters);
-            if (this._timeout && this._onTimeout) {
-                var timeoutId = window.setTimeout(this._onTimeout, this._timeout);
-            }
+            this._startXHR();
+            this._startTimeout();
         } catch (e) {
             //_onError//_onError
             this._onException(this._xhr, this._context, "myfaces._impl.xhrCore._AjaxRequest",
"send", e);
         }
     },
 
-    abort: function() {
-        try {
-            if (this._xhr.readyState > 0
-                    && this._xhr.readyState < 4) {
-                this._xhr.abort();
-            }
-        } catch (e) {
+    /**
+     * starts the asynchronous xhr request
+     */
+    _startXHR: function() {
+        var _Lang = myfaces._impl._util._Lang;
+        this._xhr = myfaces._impl.core._Runtime.getXHRObject();
+
+        this._xhr.open(this._ajaxType, this._sourceForm.action, true);
+
+        var contentType = this._contentType;
+        if (this._encoding) {
+            contentType = contentType + "; charset:" + this._encoding;
         }
-    },
 
+        this._xhr.setRequestHeader(this._CONTENT_TYPE, this._contentType);
+        this._xhr.setRequestHeader(this._HEAD_FACES_REQ, this._VAL_AJAX);
+
+        this._xhr.onreadystatechange = _Lang.hitch(this, this.callback);
+        var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
+        _Impl.sendEvent(this._xhr, this._context, myfaces._impl.core.Impl.BEGIN);
+        this._xhr.send(this._requestParameters);
+    },
 
     /**
+     * starts the timeout
+     * which is able to terminate the xhr upfront early
+     */
+    _startTimeout: function() {
+        var _Lang = myfaces._impl._util._Lang;
+        if (this._timeout && this._onTimeout) {
+            var _req = this._xhr;
+            var _context = this._context;
+            if(this._timeoutId) {
+                window.clearTimeout(this._timeoutId);
+                this._timeoutId = null;
+            }
+            this._timeoutId = window.setTimeout(
+                //we unify the api, there must be always a request passed to the external
function
+                //and always a context, no matter what
+                    _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 {
+                                }
+                            })
+                    , this._timeout);
+        }
+    },
+   
+    /**
      * Callback method to process the Ajax response
      * triggered by RequestQueue
      */
@@ -159,6 +185,12 @@ myfaces._impl.core._Runtime.extendClass(
             var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
 
             if (this._xhr.readyState == READY_STATE_DONE) {
+                if(this._timeoutId) {
+                    //normally the timeout should not cause anything anymore
+                    //but just to make sure
+                    window.clearTimeout(this._timeoutId);
+                    this._timeoutId = null;
+                }
                 this._onDone(this._xhr, this._context);
                 if (this._xhr.status >= 200 && this._xhr.status < 300) {
                     this._onSuccess(this._xhr, this._context);
@@ -168,6 +200,8 @@ myfaces._impl.core._Runtime.extendClass(
             }
         } catch (e) {
             this._onException(this._xhr, this._context, "myfaces._impl.xhrCore._AjaxRequest",
"callback", e);
+        } finally {
+            //final cleanup to terminate everything
         }
     },
 

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js?rev=960856&r1=960855&r2=960856&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js
(original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js
Tue Jul  6 09:40:51 2010
@@ -40,6 +40,8 @@ myfaces._impl.core._Runtime.extendClass(
             this._delayTimeoutId = window.setTimeout(
                     _Lang.hitch(this, function() {
                         this.clearDelayTimeout();
+                        //lets clear the delay time to enqueue correctly 
+                        delete request._delay;
                         this.enqueue(request);
                     }), request._delay);
         } else {
@@ -48,8 +50,8 @@ myfaces._impl.core._Runtime.extendClass(
                 this._curReq.send();
             } else {
                 this._callSuper("enqueue", request);
-                if (request._size != this._size) {
-                    this.setQueueSize(request._size);
+                if (request._queueSize != this._size) {
+                    this.setQueueSize(request._queueSize);
                 }
             }
         }

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js?rev=960856&r1=960855&r2=960856&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
(original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
Tue Jul  6 09:40:51 2010
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
-*/
+ */
 /** @namespace myfaces._impl.xhrCore._AjaxUtils */
 myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._AjaxUtils", Object, {
     /**
@@ -38,15 +38,14 @@ myfaces._impl.core._Runtime.extendClass(
                                        parentItem, partialIds) {
         try {
             if (!parentItem) {
-                this._onWarning(request, context,"myfaces._impl.xhrCore._AjaxUtils" ,"encodeSubmittableFields
"+"Html-Component is not nested in a Form-Tag");
+                this._onWarning(request, context, "myfaces._impl.xhrCore._AjaxUtils", "encodeSubmittableFields
" + "Html-Component is not nested in a Form-Tag");
                 return null;
             }
 
             var strBuf = [];
 
             if (partialIds && partialIds.length > 0) {
-                // recursivly check items
-                this.encodePartialSubmit(parentItem, false, partialIds, strBuf);
+                this.encodePartialSubmit(parentItem, item, false, partialIds, strBuf);
             } else {
                 // add all nodes
                 var eLen = parentItem.elements.length;
@@ -55,109 +54,117 @@ myfaces._impl.core._Runtime.extendClass(
                 } // end of for (formElements)
             }
 
-            // if triggered by a Button send it along
-            if (item && item.type && item.type.toLowerCase() == "submit")
{
-                strBuf.push(encodeURIComponent(item.name));
-                strBuf.push("=");
-                strBuf.push(encodeURIComponent(item.value));
-                strBuf.push("&");
-            }
-            //we we might have a trailing ambersant 
-            //https://issues.apache.org/jira/browse/MYFACES-2767
-            if(strBuf && strBuf.length && strBuf[strBuf.length - 1] == "&")
{
-                strBuf = strBuf.slice(0, strBuf.length - 1);
-            }
+            this.appendIssuingItem(item, strBuf);
 
-            return strBuf.join("");
+            return strBuf.join("&");
         } catch (e) {
-            this._onException(request, context,"myfaces._impl.xhrCore._AjaxUtils" ,"encodeSubmittableFields",
e);
+            this._onException(request, context, "myfaces._impl.xhrCore._AjaxUtils", "encodeSubmittableFields",
e);
         }
     },
 
     /**
      * checks recursively if contained in PPS
+     * the algorithm is as follows we have an issuing item
+     * the parent form of the issuing item and a set of child ids which do not
+     * have to be inputs, we scan now for those ids and all inputs which are childs
+     * of those ids
+     *
+     * Now this algorithm is up for discussion because it is relatively complex
+     * but for now we will leave it as it is.
+     *
      * @param {Node} node - the root node of the partial page submit
      * @param {boolean} submitAll - if set to true, all elements within this node will
      * be added to the partial page submit
      * @param {Array} partialIds - an array of partial ids which should be used for the submit
      * @param {Array} strBuf a target string buffer which receives the encoded elements
      */
-    encodePartialSubmit : function(node, submitAll,
+    encodePartialSubmit : function(node, issuingItem, submitAll,
                                    partialIds, strBuf) {
         var _Lang = myfaces._impl._util._Lang;
         var _Impl = myfaces._impl.core.Impl;
         var _Dom = myfaces._impl._util._Dom;
 
-        var nodeFilter = function(curNode) {
-            //TODO bomb out if the element is not one of the input types
-            //((elementTagName == "input" || elementTagName == "textarea" || elementTagName
== "select") &&
-            //    (elementName != null && elementName != "")) && !element.disabled
-            //
-            
+        var partialIdsFilter = function(curNode) {
             if (curNode.nodeType != 1) return false;
             if (submitAll && node != curNode) return true;
 
-            var id = curNode.id;
-            var name = curNode.name;
+            var id = curNode.id || curNode.name;
 
-            var ppsElement = id && _Lang.contains(partialIds, id);
-            return  ppsElement || (name != null && name == _Impl.P_VIEWSTATE);
+            return (id && _Lang.contains(partialIds, id)) || id == _Impl.P_VIEWSTATE;
         };
 
-        var nodes = _Dom.findAll(node, nodeFilter, true);
-        //TODO drag the encodeElement in the nodeFilter so that
-        //we have the entire processing in one loop
-        if (nodes) {
+        //shallow scan because we have a second scanning step, to find the encodable childs
of
+        //the result nodes, that way we can reduce the number of nodes
+        var nodes = _Dom.findAll(node, partialIdsFilter, false);
+
+        var allowedTagNames = {"input":true, "select":true, "textarea":true};
+
+        if (nodes && nodes.length) {
             for (var cnt = 0; cnt < nodes.length; cnt++) {
-                this.encodeElement(nodes[cnt], strBuf);
+                //we can shortcut the form any other nodetype
+                //must get a separate investigation
+                var subNodes = (nodes[cnt].tagName.toLowerCase() == "form") ?
+                        node.elements :
+                        _Dom.findByTagNames(nodes[cnt], allowedTagNames, true);
+
+                if (subNodes && subNodes.length) {
+                    for (var cnt2 = 0; cnt2 < subNodes.length; cnt2++) {
+                        this.encodeElement(subNodes[cnt2], strBuf);
+                    }
+                } else {
+                    this.encodeElement(nodes[cnt], strBuf);
+                }
             }
         }
+
+        this.appendViewState(node, strBuf);
     },
 
     /**
-     * checks recursively if contained in PPS
-     * @param {} node -
-     * @param {} insideSubmittedPart -
-     * @param {} partialIds -
-     * @param {} stringBuffer -
-     */
-    /*addNodes : function(node, insideSubmittedPart,
-     partialIds, stringBuffer) {
-     if (node != null && node.childNodes != null) {
-     var nLen = node.childNodes.length;
-     for (var i = 0; i < nLen; i++) {
-     var child = node.childNodes[i];
-     var id = child.id;
-     var elementName = child.name;
-     if (child.nodeType == 1) {
-     var isPartialSubmitContainer = ((id != null)
-     && myfaces._impl._util._Lang.arrayContains(partialIds, id));
-     if (insideSubmittedPart
-     || isPartialSubmitContainer
-     || (elementName != null
-     && elementName == myfaces._impl.core.Impl._PROP_VIEWSTATE)) {
-     // node required for PPS
-     this.addField(child, stringBuffer);
-     if (insideSubmittedPart || isPartialSubmitContainer) {
-     // check for further children
-     this.addNodes(child, true, partialIds, stringBuffer);
-     }
-     } else {
-     // check for further children
-     this.addNodes(child, false, partialIds, stringBuffer);
-     }
-     }
-     }
-     }
-     },*/
-
-    /**
-     * add a single field to stringbuffer for param submission
-     * @param {Node} element -
-     * @param {} strBuf -
+     * appends the viewstate element if not given already
+     *
+     * @param parentNode
+     * @param strBuf
+     */
+    appendViewState: function(parentNode, strBuf) {
+        var _Dom = myfaces._impl._util._Dom;
+        var _Impl = myfaces._impl.core.Impl;
+
+        //viewstate covered, do a preemptive check
+        if (strBuf.join("").indexOf(_Impl.P_VIEWSTATE) != -1) return;
+
+        var viewStates = _Dom.findByName(parentNode, _Impl.P_VIEWSTATE, true);
+        if (viewStates && viewStates.length) {
+            for (var cnt2 = 0; cnt2 < viewStates.length; cnt2++) {
+                this.encodeElement(viewStates[cnt2], strBuf);
+            }
+        }
+    },
+
+    /**
+     * appends the issuing item if not given already
+     * @param item
+     * @param strBuf
+     */
+    appendIssuingItem: function (item, strBuf) {
+        // if triggered by a Button send it along
+        if (item && item.type && item.type.toLowerCase() == "submit") {
+            strBuf.push(encodeURIComponent(item.name));
+            strBuf.push("=");
+            strBuf.push(encodeURIComponent(item.value));
+
+        }
+    },
+
+
+    /**
+     * encodes a single input element for submission
+     *
+     * @param {Node} element - to be encoded
+     * @param {} strBuf - a target array buffer receiving the encoded strings
      */
     encodeElement : function(element, strBuf) {
-        var name = (null != element.name || 'undefined' != typeof element.name) ? element.name
: element.id;
+        var name = element.name || element.id;
         var tagName = element.tagName.toLowerCase();
         var elemType = element.type;
         if (elemType != null) {
@@ -187,16 +194,17 @@ myfaces._impl.core._Runtime.extendClass(
                     for (var u = 0; u < uLen; u++) {
                         // find all selected options
                         if (element.options[u].selected) {
+                            var subBuf = [];
                             var elementOption = element.options[u];
-                            strBuf.push(encodeURIComponent(name));
-                            strBuf.push("=");
+                            subBuf.push(encodeURIComponent(name));
+                            subBuf.push("=");
                             if (elementOption.getAttribute("value") != null) {
-                                strBuf.push(encodeURIComponent(elementOption.value));
+                                subBuf.push(encodeURIComponent(elementOption.value));
                             } else {
-                                strBuf.push(encodeURIComponent(elementOption.text));
+                                subBuf.push(encodeURIComponent(elementOption.text));
                             }
-                            strBuf.push("&");
-                        }
+
+                        }  strBuf.push(subBuf.join(""));
                     }
                 }
             }
@@ -208,10 +216,12 @@ myfaces._impl.core._Runtime.extendClass(
             if ((tagName != "select" && elemType != "button"
                     && elemType != "reset" && elemType != "submit" &&
elemType != "image")
                     && ((elemType != "checkbox" && elemType != "radio") ||
element.checked)) {
-                strBuf.push(encodeURIComponent(name));
-                strBuf.push("=");
-                strBuf.push(encodeURIComponent(element.value));
-                strBuf.push("&");
+                var subBuf = [];
+                subBuf.push(encodeURIComponent(name));
+                subBuf.push("=");
+                subBuf.push(encodeURIComponent(element.value));
+                strBuf.push(subBuf.join(""));
+
             }
 
         }

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js?rev=960856&r1=960855&r2=960856&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js
(original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js
Tue Jul  6 09:40:51 2010
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
-*/
+ */
 /**
  * The xhr core adapter
  * which provides the transport mechanisms to the calling
@@ -113,6 +113,9 @@ myfaces._impl.core._Runtime.extendClass(
 
             //standard timeout callback
             "onTimeout": this._Lang.hitch(this, this._stdOnTimeout),
+
+            //now to the internal error handlers which perform operations
+            //on the queue
             //standard exception handling callback
             "onException": this._Lang.hitch(this, this._stdErrorHandler),
             //standard warning handling callback
@@ -121,14 +124,14 @@ myfaces._impl.core._Runtime.extendClass(
 
         //we now mix in the config settings which might either be set globally
         //or pushed in under the context myfaces.<contextValue> into the current request

-        this._applyConfig(ret, "alarmThreshold", this._PAR_ERRORLEVEL);
-        this._applyConfig(ret, "queueSize", this._PAR_QUEUESIZE);
-        this._applyConfig(ret, "timeout", this._PAR_TIMEOUT);
-        this._applyConfig(ret, "delay", this._PAR_DELAY);
+        this._applyConfig(ret, context, "alarmThreshold", this._PAR_ERRORLEVEL);
+        this._applyConfig(ret, context, "queueSize", this._PAR_QUEUESIZE);
+        this._applyConfig(ret, context, "timeout", this._PAR_TIMEOUT);
+        this._applyConfig(ret, context, "delay", this._PAR_DELAY);
 
         //now partial page submit needs a different treatment
         //since pps == execute strings
-        if (_getConfig(context, this._PAR_PPS, null) != null
+        if (_getConfig(context, this._PAR_PPS, false)
                 && _Lang.exists(passThrgh, myfaces._impl.core.Impl.P_EXECUTE)
                 && passThrgh[myfaces._impl.core.Impl.P_EXECUTE].length > 0) {
             ret['partialIdsArray'] = passThrgh[myfaces._impl.core.Impl.P_EXECUTE].split("
");
@@ -140,14 +143,15 @@ myfaces._impl.core._Runtime.extendClass(
      * helper method to apply a config setting to our varargs param list
      *
      * @param destination the destination map to receive the setting
+     * @param context the current context
      * @param destParm the destination param of the destination map
      * @param srcParm the source param which is the key to our config setting
      */
-    _applyConfig: function(destination, destParm, srcParm) {
+    _applyConfig: function(destination, context, destParm, srcParm) {
         var _RT = myfaces._impl.core._Runtime;
         var _getConfig = _RT.getLocalOrGlobalConfig;
-        if (_getConfig(this._context, srcParm, null) != null) {
-            destination[destParm] = _getConfig(this._context, srcParm, null);
+        if (_getConfig(context, srcParm, null) != null) {
+            destination[destParm] = _getConfig(context, srcParm, null);
         }
     },
 
@@ -173,11 +177,13 @@ myfaces._impl.core._Runtime.extendClass(
     _stdOnSuccess: function(request, context) {
         //_onSuccess
         this._loadImpl();
-
-        this._Impl.response(request, context);
-        this._Impl.sendEvent(request, context, this._Impl.SUCCESS);
-        this._q.processQueue();
-
+        try {
+            this._Impl.response(request, context);
+          
+            this._Impl.sendEvent(request, context, this._Impl.SUCCESS);
+        } finally {
+            this._q.processQueue();
+        }
     },
 
     /**
@@ -212,15 +218,28 @@ myfaces._impl.core._Runtime.extendClass(
 
     /**
      * standard timeout handler
+     * the details on how to handle the timeout are
+     * handled by the calling request object
      */
-    _stdOnTimeout: function() {
-        this._q._curReq.abort();
+    _stdOnTimeout: function(request, context) {
+        this._loadImpl();
+        try {
+            //we issue an event not an error here before killing the xhr process
+            this._Impl.sendEvent(request, context, this._Impl.TIMEOUT_EVENT,
+                    this._Impl.TIMEOUT_EVENT);
+            //timeout done we process the next in the queue
+        } finally {
+            //We trigger the next one in the queue
+            this._q.processQueue();
+        }
+        //ready state done should be called automatically
     },
 
     /**
      * Client error handlers which also in the long run route into our error queue
      * but also are able to deliver more meaningful messages
-     *
+     * note, in case of an error all subsequent xhr requests are dropped
+     * to get a clean state on things
      *
      * @param request the xhr request object
      * @param context the context holding all values for further processing
@@ -230,39 +249,23 @@ myfaces._impl.core._Runtime.extendClass(
      */
     _stdErrorHandler: function(request, context, sourceClass, func, exception) {
         this._loadImpl();
-        
-        if (this._threshold == "ERROR" && !exception._processed) {
-            this._Impl.sendError(request, context, this._Impl.CLIENT_ERROR, exception.name,
-                    "MyFaces ERROR:" + this._Lang.createErrorMsg(sourceClass, func, exception));
-        }
-        this._q.cleanup();
-        //we forward the exception, just in case so that the client
-        //will receive it in any way
-        exception._processed = true;
-        throw exception;
-    },
-
-    /**
-     * Standard non blocking warnings handler
-     *
-     * @param request the xhr request object
-     * @param context the context holding all values for further processing
-     * @param sourceClass (String) the issuing class for a more meaningful message
-     * @param func the issuing function
-     * @param exception the embedded exception
-     */
-    _stdWarningsHandler: function(request, context, sourceClass, func, exception) {
-        this._loadImpl();
-
-        if (this._threshold == "WARNING" || this._threshold == "ERROR") {
-            this._Impl.sendError(request, context, this._Impl.CLIENT_ERROR, exception.name,
-                    "MyFaces WARNING:" + this._Lang.createErrorMsg(sourceClass, func, exception));
+        try {
+            if (this._threshold == "ERROR" && !exception._processed) {
+                this._Impl.sendError(request, context, this._Impl.CLIENT_ERROR, exception.name,
+                        "MyFaces ERROR:" + this._Lang.createErrorMsg(sourceClass, func, exception));
+            }
+        } finally {
+            this._q.cleanup();
+            //we forward the exception, just in case so that the client
+            //will receive it in any way
+            exception._processed = true;
+            throw exception;
         }
-        this.destroy();
     },
+   
 
     _loadImpl: function() {
-        if(!this._Impl) {
+        if (!this._Impl) {
             this._Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
         }
         return this._Impl;



Mime
View raw message