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/05/17 12:48:59 UTC

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

Author: werpu
Date: Mon May 17 10:48:59 2010
New Revision: 945075

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

The transport layer part is now cleaned up, almost all functionality now is in Transport.js which is implementation specific
the ajax request object now is a plain request object (well not entirely yet, but very close, the last functionality soon will be moved outside)

The entire error handling aspect has improved to a big degree now, we have unified error messages in most areas,
the errors are enabled on level ERROR (used to be disabled)
but there is still room for improvement.

Unfortunately there is not too much I can do regarding the final filesizes without sacrificing readability, or functionality.
Since the server side gzipped file is around 17KB while our runtime jsf.js file is 70Kbyte (Mojarras is probably around 30) kbyte
we have some tradeoff, but on the other hand I think the long term maintainability is way better in our
environment, especially if other transport mechanisms are plugged in soon.

Added:
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js
Modified:
    myfaces/core/trunk/api/src/assembler/jsfscripts-compiler.xml
    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/_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/_AjaxResponse.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js

Modified: myfaces/core/trunk/api/src/assembler/jsfscripts-compiler.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/assembler/jsfscripts-compiler.xml?rev=945075&r1=945074&r2=945075&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/assembler/jsfscripts-compiler.xml (original)
+++ myfaces/core/trunk/api/src/assembler/jsfscripts-compiler.xml Mon May 17 10:48:59 2010
@@ -12,13 +12,11 @@
             <script type = "text/javascript" src = "./myfaces/_impl/_util/_ListenerQueue.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/_util/_Dom.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/_util/_HtmlStripper.js"></script>
-
-            <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_Exception.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_AjaxUtils.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_AjaxRequestQueue.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_AjaxRequest.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_AjaxResponse.js"></script>
-            <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_xhrCoreAdapter.js"></script>
+            <script type = "text/javascript" src = "./myfaces/_impl/xhrCore/_Transport.js"></script>
             <script type = "text/javascript" src = "./myfaces/_impl/core/Impl.js"></script>
             <script type = "text/javascript" src = "./myfaces/api/jsf.js"></script>
         -->
@@ -32,12 +30,11 @@
                 <include>**/_impl/_util/_ListenerQueue.js</include>
                 <include>**/_impl/_util/_Dom.js</include>
                 <include>**/_impl/_util/_HtmlStripper.js</include>
-                <include>**/_impl/xhrCore/_Exception.js</include>
                 <include>**/_impl/xhrCore/_AjaxUtils.js</include>
                 <include>**/_impl/xhrCore/_AjaxRequestQueue.js</include>
                 <include>**/_impl/xhrCore/_AjaxRequest.js</include>
                 <include>**/_impl/xhrCore/_AjaxResponse.js</include>
-                <include>**/_impl/xhrCore/_xhrCoreAdapter.js</include>
+                <include>**/_impl/xhrCore/_Transports.js</include>
                 <include>**/_impl/core/Impl.js</include>
                 <include>**/api/jsf.js</include>
             </includes>

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=945075&r1=945074&r2=945075&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 May 17 10:48:59 2010
@@ -78,7 +78,6 @@ myfaces._impl.core._Runtime.singletonExt
      *
      * @param source
      * @param destination
-     * @param strongCompare
      */
     equalsIgnoreCase: function(source, destination) {
         //either both are not set or null
@@ -387,24 +386,6 @@ myfaces._impl.core._Runtime.singletonExt
     },
 
     /**
-     * [STATIC]
-     * static method used by static methods that throw errors
-     */
-    throwNewError : function(request, context, sourceClass, func, exception) {
-        var newException = new myfaces._impl.xhrCore._Exception(request, context, sourceClass, "ERROR");
-        newException.throwError(request, context, func, exception);
-    },
-
-    /**
-     * [STATIC]
-     * static method used by static methods that throw warnings
-     */
-    throwNewWarning: function(request, context, sourceClass, func, message) {
-        var newException = new myfaces._impl.xhrCore._Exception(request, context, sourceClass, "WARNING");
-        newException.throwWarning(request, context, func, message);
-    },
-
-    /**
      * onload wrapper for chaining the onload cleanly
      * @param func the function which should be added to the load
      * chain (note we cannot rely on return values here, hence jsf.util.chain will fail)
@@ -461,70 +442,118 @@ myfaces._impl.core._Runtime.singletonExt
     /**
      * attaches a standard iterator if
      * the collection does not have one already
-     * 
+     *
      * @param inColl
      */
-  /*  attachIterators : function (inColl ) {
-        var _coll = inColl;
+    /*  attachIterators : function (inColl ) {
+     var _coll = inColl;
 
-        if(_coll instanceof Array) {
-            if(!_coll.each) {
-                _coll.each = function(closure) {
-                    for(var cnt = 0; cnt < _coll.length; cnt++) {
-                        closure(_coll[cnt]);
-                    }
-                }
-            }
-            if(!_coll.filter) {
-                _coll.filter = function(closure) {
-                    var retVal = [];
-                    for(var cnt = 0; cnt < _coll.length; cnt++) {
-                        var elem = closure(_coll[cnt]);
-                        if(closure(elem)) {
-                            retVal.push(elem)
-                        }
-                    }
-                }
-            }
+     if(_coll instanceof Array) {
+     if(!_coll.each) {
+     _coll.each = function(closure) {
+     for(var cnt = 0; cnt < _coll.length; cnt++) {
+     closure(_coll[cnt]);
+     }
+     }
+     }
+     if(!_coll.filter) {
+     _coll.filter = function(closure) {
+     var retVal = [];
+     for(var cnt = 0; cnt < _coll.length; cnt++) {
+     var elem = closure(_coll[cnt]);
+     if(closure(elem)) {
+     retVal.push(elem)
+     }
+     }
+     }
+     }
+
+     } else {
+     if(!_coll.each) {
+     _coll.each = function(closure) {
+     for(var key in _coll.length) {
+     closure(key, _coll[key]);
+     }
+     }
+     }
+     if(!_coll.filter) {
+     _coll.filter = function(closure) {
+     var retVal = [];
+     for(var key in _coll.length) {
+     var elem = closure(_coll[key]);
+     if(closure(key, elem)) {
+     retVal.push(elem)
+     }
+     }
+     }
+     }
 
-        } else {
-            if(!_coll.each) {
-                _coll.each = function(closure) {
-                    for(var key in _coll.length) {
-                        closure(key, _coll[key]);
-                    }
-                }
-            }
-            if(!_coll.filter) {
-                _coll.filter = function(closure) {
-                    var retVal = [];
-                    for(var key in _coll.length) {
-                        var elem = closure(_coll[key]);
-                        if(closure(key, elem)) {
-                            retVal.push(elem)
-                        }
-                    }
-                }
-            }
-
-        }
-    },  */
+     }
+     },  */
 
     /**
-     * helper to automatically apply a delivered arguments map
+     * helper to automatically apply a delivered arguments map or array
      * to its destination which has a field "_"<key>
      *
      * @param destination the destination object
-     * @param args the arguments array
+     * @param args the arguments array or map
      * @param argNames the argument names to be transferred
      */
     applyArguments: function(destination, args, argNames) {
-        for(var cnt = 0; cnt < args.length ; cnt++) {
-            if('undefined' != typeof destination["_"+argNames[cnt]]) {
-                destination["_"+argNames[cnt]] = args[cnt];
+        if (argNames) {
+            for (var cnt = 0; cnt < args.length; cnt++) {
+                if ('undefined' != typeof destination["_" + argNames[cnt]]) {
+                    destination["_" + argNames[cnt]] = args[cnt];
+                }
+            }
+        } else {
+            for (var key in args) {
+                if ('undefined' != typeof destination["_" +key]) {
+                    destination["_" + key] = args[key];
+                }
             }
         }
     },
+    /**
+     * creates a standardized error message which can be reused by the system
+     *
+     * @param sourceClass the source class issuing the exception
+     * @param func the function issuing the exception
+     * @param error the error object itself (optional)
+     */
+    createErrorMessage: function(sourceClass, func, error) {
+        var retVal = [];
+
+        retVal.push(this.keyValToStr("Affected Class: ", sourceClass));
+        retVal.push(this.keyValToStr("Affected Method: ", func));
+
+        if (error) {
+            retVal.push(this.keyValToStr("Error name: ", error.name ? error.name : "undefined"));
+            retVal.push(this.keyValToStr("Error message: ", error.message ? error.message : "undefined"));
+            retVal.push(this.keyValToStr("Error description: ", error.description ? error.description : "undefined"));
+            retVal.push(this.keyValToStr("Error number: ", 'undefined' != typeof error.number ? error.number : "undefined"));
+            retVal.push(this.keyValToStr("Error line number: ", 'undefined' != typeof error.lineNumber ? error.lineNumber : "undefined"));
+        }
+        return retVal.join("");
+    },
+
+    /**
+     * transforms a key value pair into a string
+     * @param key the key
+     * @param val the value
+     * @param delimiter the delimiter
+     */
+    keyValToStr: function(key, val, delimiter) {
+        var retVal = [];
+        retVal.push(key);
+        retVal.push(val);
+        if ('undefined' == typeof delimiter) {
+            delimiter = "\n";
+        }
+        retVal.push(delimiter);
+        return retVal.join("");
+    },
+
 
     logLog: function(/*varargs*/) {
         var argumentStr = this.objToArray(arguments).join(" ");

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=945075&r1=945074&r2=945075&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 May 17 10:48:59 2010
@@ -15,7 +15,7 @@
 myfaces._impl.core._Runtime.singletonExtendClass("myfaces._impl.core.Impl", Object, {
 
     //third option myfaces._impl.xhrCoreAjax which will be the new core impl for now
-    _transport : new (myfaces._impl.core._Runtime.getGlobalConfig("transport", myfaces._impl.xhrCore._Ajax))(),
+    _transport : new (myfaces._impl.core._Runtime.getGlobalConfig("transport", myfaces._impl.xhrCore._Transports))(),
 
     /**
      * external event listener queue!

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=945075&r1=945074&r2=945075&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 Mon May 17 10:48:59 2010
@@ -489,9 +489,9 @@ if ('undefined' == typeof  myfaces._impl
         }
 
         //we now map the function map in
-        if ('undefined' != typeof prototypeFunctions  && null != prototypeFunctions) {
+        if ('undefined' != typeof prototypeFunctions && null != prototypeFunctions) {
             for (var key in prototypeFunctions) {
-                if( key != "_callSuper") {
+                if (key != "_callSuper") {
                     newClass.prototype[key] = prototypeFunctions[key];
                 }
             }
@@ -503,7 +503,7 @@ if ('undefined' == typeof  myfaces._impl
         }
         return newClass;
     };
-    
+
     /**
      * determines if the embedded scripts have to be evaled manually
      * @return true if a browser combination is given which has to

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=945075&r1=945074&r2=945075&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 Mon May 17 10:48:59 2010
@@ -13,22 +13,31 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- * Author: Ganesh Jung (latest modification by $Author: ganeshpuri $)
- * Version: $Revision: 1.4 $ $Date: 2009/05/31 09:16:44 $
  *
  */
+
 /**
- * an implementation of a queued
- * asynchronoues request 
+ * 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 $
  */
 myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._AjaxRequest", Object, {
+
+    /*all instance vars can be set from the outside
+     * via a parameter map*/
     _contentType: "application/x-www-form-urlencoded",
     _source: null,
     _xhr: null,
-    _partialIdsArray: null,
-    _queueSize: -1,
+    _encoding:null ,
+
     _context:null,
-    response: null,
     _ajaxUtil: null,
     _sourceForm: null,
     _passThrough: null,
@@ -36,59 +45,54 @@ myfaces._impl.core._Runtime.extendClass(
     _exception: null,
     _timeout: null,
     _delay:null,
+
+
     _partialIdsArray : null,
-    _alarmThreshold : "ERROR",
-    _xhrQueue: null,
+    _ajaxType: "POST",
 
 
-    _PAR_ERRORLEVEL:"errorlevel",
-    _PAR_QUEUESIZE:"queuesize",
-    _PAR_PPS:"pps",
-    _PAR_TIMEOUT:"timeout",
-    _PAR_DELAY:"delay",
+    //callbacks for onDone... done issues
+    //onSuccess everything has passed through
+    //onError server side error
+
+    //onException exception thrown by the client
+    //onWarning warning issued by the client
+    _onDone : null,
+    _onSuccess: null,
+    _onError: null,
+    _onException: null,
+    _onWarning: null,
+
+    /*response object which is exposed to the queue*/
+    _response: null,
 
-    _HEAD_POST: "POST",
-    _HEAD_TYPE:"Content-Type",
-    _HEAD_FACES_REQ:"Faces-Request",
 
+    /*
+     * constants used internally 
+     */
+    _CONTENT_TYPE:"Content-Type",
+    _HEAD_FACES_REQ:"Faces-Request",
     _VAL_AJAX: "partial/ajax",
 
     /**
      * Constructor
-     * @param {Node} source - Item that triggered the request
-     * @param {Node} sourceForm (form) - Form containing source
-     * @param {Object} context (Map) - AJAX context
-     * @param {Object} passThrough (Map) - parameters to pass through to the server (execute/render)
+     * @arguments  an arguments map which an override any of the given protected
+     * instance variables, by a simple name value pair combination
+     *
      */
-    constructor_: function(source, sourceForm, context, passThrough, queue) {
-        this._exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxRequest", this._alarmThreshold);
+    constructor_: function(arguments) {
         try {
 
             /*namespace remapping for readability*/
-            var _Runtime = myfaces._impl.core._Runtime;
             var _Lang = myfaces._impl._util._Lang;
-            var _getConfig = _Runtime.getLocalOrGlobalConfig;
-
-            _Lang.applyArguments(this, arguments, ["source", "sourceForm", "context", "passThrough", "xhrQueue"]);
-
-            //this._source = source;
-            // myfaces parameters
-            //this._partialIdsArray = null;
-            //this._queueSize = -1;
+            //we fetch in the standard arguments
+            _Lang.applyArguments(this, arguments);
 
-            this._applyConfig("_alarmThreshold", this._PAR_ERRORLEVEL);
-            this._applyConfig("_queueSize", this._PAR_QUEUESIZE);
-            this._applyConfig("_timeout", this._PAR_TIMEOUT);
-            this._applyConfig("_delay", this._PAR_DELAY);
-
-            if (_getConfig(context, this._PAR_PPS, null) != null
-                    && _Lang.exists(passThrough, myfaces._impl.core.Impl._PROP_EXECUTE)
-                    && passThrough[myfaces._impl.core.Impl._PROP_EXECUTE].length > 0) {
-                this._partialIdsArray = passThrough[myfaces._impl.core.Impl._PROP_EXECUTE].split(" ");
+            //if our response handler is not set
+            if (!this._response) {
+                this._response = new myfaces._impl.xhrCore._AjaxResponse(this._onException, this._onWarning);
             }
-
-            this.response = new myfaces._impl.xhrCore._AjaxResponse(this._alarmThreshold);
-            this._ajaxUtil = new myfaces._impl.xhrCore._AjaxUtils(this._alarmThreshold);
+            this._ajaxUtil = new myfaces._impl.xhrCore._AjaxUtils(this._onException, this._onWarning);
 
             this._requestParameters = this.getViewState();
 
@@ -97,18 +101,9 @@ myfaces._impl.core._Runtime.extendClass(
                         "&" + encodeURIComponent(key) +
                         "=" + encodeURIComponent(this._passThrough[key]);
             }
-
         } catch (e) {
             //_onError
-            this._exception.throwError(null, context, "Ctor", e);
-        }
-    },
-
-    _applyConfig: function(destParm, srcParm) {
-        var _Runtime = myfaces._impl.core._Runtime;
-        var _getConfig = _Runtime.getLocalOrGlobalConfig;
-        if (_getConfig(this._context, srcParm, null) != null) {
-            this[destParm] = _getConfig(this._context, srcParm, null);
+            this._onException(null, this._context, "myfaces._impl.xhrCore._AjaxRequest", "constructor", e);
         }
     },
 
@@ -116,37 +111,45 @@ 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._HEAD_POST, this._sourceForm.action, true);
-            this._xhr.setRequestHeader(this._HEAD_TYPE, this._contentType);
+            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 = this._xhrQueue.handleCallback;
+            this._xhr.onreadystatechange = _Lang.hitch(this, this.requestCallback);
             var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
             _Impl.sendEvent(this._xhr, this._context, myfaces._impl.core.Impl._AJAX_STAGE_BEGIN);
             this._xhr.send(this._requestParameters);
-            if ('undefined' != typeof this._timeout) {
-                var timeoutId = window.setTimeout(
-                        function() {
-                            try {
-                                if (this._xhrQueue._curReq._xhr.readyState > 0
-                                        && this._xhrQueue._curReq._xhr.readyState < 4) {
-                                    this._xhrQueue._curReq._xhr.abort();
-                                }
-                            } catch (e) {
-                                // don't care about exceptions here
-                            }
-                        }, this._timeout);
+            if (this._timeout && this._onTimeout) {
+                var timeoutId = window.setTimeout(this._onTimeout, this._timeout);
             }
         } catch (e) {
             //_onError//_onError
-            this._exception.throwError(this._xhr, this._context, "send", e);
+            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) {
+        }
+    },
+
+
     /**
      * Callback method to process the Ajax response
      * triggered by RequestQueue
@@ -154,40 +157,18 @@ myfaces._impl.core._Runtime.extendClass(
     requestCallback : function() {
         var READY_STATE_DONE = 4;
         try {
-            //local namespace remapping
             var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
 
             if (this._xhr.readyState == READY_STATE_DONE) {
-                //_onDone
-                _Impl.sendEvent(this._xhr, this._context, myfaces._impl.core.Impl._AJAX_STAGE_COMPLETE);
-
+                this._onDone(this._xhr, this._context);
                 if (this._xhr.status >= 200 && this._xhr.status < 300) {
-                     //_onSuccess
-                    _Impl.response(this._xhr, this._context);
-                    _Impl.sendEvent(this._xhr, this._context, myfaces._impl.core.Impl._AJAX_STAGE_SUCCESS);
-                    this._xhrQueue.processQueue();
+                    this._onSuccess(this._xhr, this._context);
                 } else {
-                    //_onError
-                    var errorText;
-                    try {
-                        errorText = "Request failed";
-                        if (this._xhr.status) {
-                            errorText += "with status " + this._xhr.status;
-                            if (this._xhr.statusText) {
-                                errorText += " and reason " + this._xhr.statusText;
-                            }
-                        }
-                    } catch (e) {
-                        errorText = "Request failed with unknown status";
-                    }
-                    //_onError
-                    _Impl.sendError(this._xhr, this._context, myfaces._impl.core.Impl._ERROR_HTTPERROR,
-                            myfaces._impl.core.Impl._ERROR_HTTPERROR, errorText);
+                    this._onError(this._xhr, this._context);
                 }
             }
         } catch (e) {
-            //_onError
-            this._exception.throwError(this._xhr, this._context, "requestCallback", e);
+            this._onException(this._xhr, this._context, "myfaces._impl.xhrCore._AjaxRequest", "requestCallback", e);
         }
     },
 

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=945075&r1=945074&r2=945075&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 Mon May 17 10:48:59 2010
@@ -23,30 +23,6 @@ myfaces._impl.core._Runtime.extendClass(
 
     constructor_: function(){
         this._callSuper("constructor");
-
-        var _this = this;
-
-        var _handleCallback = this.handleCallback;
-        //we have to scope this because the xhr request will change the
-        //callback scope to window from outside, hence we have to enforce a scope here
-        this.handleCallback = myfaces._impl._util._Lang.hitch(_this, _handleCallback);
-    },
-
-    /**
-     *
-     * provides api callback
-     *
-     * we have to hitch this function since
-     * the xhr request changes scopes
-     * in the asynchronous case, the callback always
-     * has to reference this
-     */
-    handleCallback : function() {
-
-        if (this._curReq != null) {
-            this._curReq.requestCallback();
-            //this.processQueue();
-        }
     },
 
     /**
@@ -118,8 +94,3 @@ myfaces._impl.core._Runtime.extendClass(
     }
 });
 
-//TODO replace this with a singleton hooked to the direct xhr object
-//instead of one hooked to the qeue
-if (myfaces._impl.core._Runtime.reserveNamespace("myfaces._impl.xhrCore._RQInstance")) {
-    myfaces._impl.xhrCore._RQInstance = new myfaces._impl.xhrCore._AjaxRequestQueue();
-}
\ No newline at end of file

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=945075&r1=945074&r2=945075&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 May 17 10:48:59 2010
@@ -21,17 +21,7 @@
 myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._AjaxResponse", Object, {
 
 
-    /**
-     * Constructor
-     * @param {String} alarmThreshold
-     */
-    constructor_: function(alarmThreshold) {
-        this.alarmThreshold = alarmThreshold;
-        this._exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxResponse", this.alarmThreshold);
-        //change tracer for post changes operations
-        this.changeTrace = [];
-        this.appliedViewState = null;
-    },
+
 
     /*partial response types*/
     _RESPONSE_PARTIAL : "partial-response",
@@ -57,6 +47,19 @@ myfaces._impl.core._Runtime.extendClass(
     _PROP_VIEWROOT: "javax.faces.ViewRoot",
     _PROP_VIEWHEAD: "javax.faces.ViewHead",
     _PROP_VIEWBODY: "javax.faces.ViewBody",
+
+    /**
+     * Constructor
+     * @param {String} alarmThreshold
+     */
+    constructor_: function(onException, onWarning) {
+
+        this.changeTrace = [];
+        this._onException = onException;
+        this._onWarning = onWarning;
+
+        this.appliedViewState = null;
+    },
     /**
      * uses response to start Html element replacement
      *
@@ -146,7 +149,7 @@ myfaces._impl.core._Runtime.extendClass(
             //fixup missing viewStates due to spec deficiencies
             this.fixViewStates();
         } catch (e) {
-            this._exception.throwError(request, context, "processResponse", e);
+            this._onException(request, context, "myfaces._impl.xhrCore._AjaxResponse", "processResponse", e);
         }
     },
 
@@ -289,7 +292,7 @@ myfaces._impl.core._Runtime.extendClass(
                     element = _Dom.getElementFromForm(this._PROP_VIEWSTATE, sourceForm, true, true);
                 } catch (e) {
                     //in case of an error here we try an early recovery but throw an error to our error handler
-                    _Lang.throwNewError(request, context, "_AjaxResponse", "processUpdate('javax.faces.ViewState')", e);
+                    this._onException(request, context, "_AjaxResponse", "processUpdate('javax.faces.ViewState')", e);
                 }
 
                 if (null == element) {//no element found we have to append a hidden field
@@ -410,12 +413,12 @@ myfaces._impl.core._Runtime.extendClass(
             var item = (!_Lang.isString(itemIdToReplace)) ? itemIdToReplace :
                     myfaces._impl._util._Dom.getElementFromForm(itemIdToReplace, form);
             if ('undefined' == typeof item || null == item) {
-                throw Error("myfaces._impl.xhrCore._AjaxResponse.prototype.replaceHtmlItem: item could not be found");
+                throw Error("myfaces._impl.xhrCore._AjaxResponse.replaceHtmlItem: item with identifier "+itemIdToReplace.toString()+" could not be found");
             }
             return myfaces._impl._util._Dom.outerHTML(item, markup);
 
         } catch (e) {
-            myfaces._impl._util._Lang.throwNewError(request, context, "Utils", "replaceHTMLItem", e);
+            this._onException(request, context, "myfaces._impl.xhrCore._AjaxResponse", "replaceHTMLItem", e);
         }
         return null;
     }

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=945075&r1=945074&r2=945075&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 Mon May 17 10:48:59 2010
@@ -23,10 +23,10 @@ myfaces._impl.core._Runtime.extendClass(
      * Constructor
      * @param {String} alarmThreshold - Error Level
      */
-    constructor_ : function(alarmThreshold) {
-        // Exception Objekt
-        this.alarmThreshold = alarmThreshold;
-        this._exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxUtils", this.alarmThreshold);
+    constructor_ : function(onException, onWarning) {
+
+        this._onException = onException;
+        this._onWarning = onWarning;
     },
 
     /**
@@ -41,8 +41,7 @@ myfaces._impl.core._Runtime.extendClass(
                                        parentItem, partialIds) {
         try {
             if (parentItem == null) {
-                this._exception.throwWarning(request, context, "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;
             }
 
@@ -69,7 +68,7 @@ myfaces._impl.core._Runtime.extendClass(
 
             return strBuf.join("");
         } catch (e) {
-            this._exception.throwError(request, context, "encodeSubmittableFields", e);
+            this._onException(request, context,"myfaces._impl.xhrCore._AjaxUtils" ,"encodeSubmittableFields", e);
         }
     },
 
@@ -119,34 +118,34 @@ myfaces._impl.core._Runtime.extendClass(
      * @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);
-                    }
-                }
-            }
-        }
-    },*/
+     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

Added: 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=945075&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js (added)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js Mon May 17 10:48:59 2010
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2009 Ganesh Jung
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ *
+ * Author: Ganesh Jung (latest modification by $Author: ganeshpuri $)
+ * Version: $Revision: 1.1 $ $Date: 2009/05/26 21:24:42 $
+ *
+ */
+/**
+ * The xhr core adapter
+ * which provides the transport mechanisms to the calling
+ * objects, and controls the queue behavior, the error handling
+ * and partial page submit functionality among other things
+ *
+ * The idea behind this is to make the ajax request object as barebones
+ * as possible and shift the extra functionality like queuing
+ * parameter handling etc... to this class so that our transports become more easily
+ * pluggable. This should keep the path open to iframe submits and other transport layers
+ *
+ * the call to the corresponding transport just should be a
+ * transport.xhrQueuedPost
+ *
+ * or transport.xhrPost,transport.xhrGet  etc... in the future
+ */
+myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._Transports"
+        , Object, {
+
+    _PAR_ERRORLEVEL:"errorlevel",
+    _PAR_QUEUESIZE:"queuesize",
+    _PAR_PPS:"pps",
+    _PAR_TIMEOUT:"timeout",
+    _PAR_DELAY:"delay",
+
+    /**
+     * a singleton queue
+     */
+    _queue: new myfaces._impl.xhrCore._AjaxRequestQueue(),
+    _threshold: "ERROR",
+
+    _Lang :  myfaces._impl._util._Lang,
+
+
+    /**
+     * mapped options already have the exec and view properly in place
+     * myfaces specifics can be found under mappedOptions.myFaces
+     * @param {Node} source the source of this call
+     * @param {Node} sourceForm the html form which is the source of this call
+     * @param {Object} context (Map) the internal pass through context
+     * @param {Object} passThroughValues (Map) values to be passed through
+     **/
+    xhrQueuedPost : function(source, sourceForm, context, passThroughValues) {
+        this._queue.enqueue(
+                new myfaces._impl.xhrCore._AjaxRequest(this._getArguments(source, sourceForm, context, passThroughValues)));
+    },
+
+    /**
+     * Spec. 13.3.3
+     * Examining the response markup and updating the DOM tree
+     * @param {XmlHttpRequest} request - the ajax request
+     * @param {XmlHttpRequest} context - the ajax context
+     */
+    response : function(request, context) {
+        this._queue._curReq._response.processResponse(request, context);
+    },
+
+    /**
+     * creates the arguments map and
+     * fetches the config params in a proper way in to
+     * deal with them in a flat way (from the nested context way)
+     *
+     * @param source the source of the request
+     * @param sourceForm the sourceform
+     * @param context   the context holding all values
+     * @param passThroughValues the passThrough values to be blended into the response
+     */
+    _getArguments: function(source, sourceForm, context, passThroughValues) {
+        var _Runtime = myfaces._impl.core._Runtime;
+        var _getConfig = _Runtime.getLocalOrGlobalConfig;
+
+        var arguments = {
+            "source": source,
+            "sourceForm": sourceForm,
+            "context": context,
+            "passThrough": passThroughValues,
+            "xhrQueue": this._queue,
+
+            //standard done callback
+            "onDone": this._Lang.hitch(this, this._stdOnDone),
+            //standard success callback
+            "onSuccess": this._Lang.hitch(this, this._stdOnSuccess),
+            //standard server side error callback
+            "onError": this._Lang.hitch(this, this._stdOnError),
+
+            //standard timeout callback
+            "onTimeout": this._Lang.hitch(this, this._stdOnTimeout),
+            //standard exception handling callback
+            "onException": this._Lang.hitch(this, this._stdErrorHandler),
+            //standard warning handling callback
+            "onWarn": this._Lang.hitch(this, this._stdErrorHandler)
+        };
+
+        //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(arguments, "alarmThreshold", this._PAR_ERRORLEVEL);
+        this._applyConfig(arguments, "queueSize", this._PAR_QUEUESIZE);
+        this._applyConfig(arguments, "timeout", this._PAR_TIMEOUT);
+        this._applyConfig(arguments, "delay", this._PAR_DELAY);
+
+        //now partial page submit needs a different treatment
+        //since pps == execute strings
+        if (_getConfig(context, this._PAR_PPS, null) != null
+                && _Lang.exists(passThrough, myfaces._impl.core.Impl._PROP_EXECUTE)
+                && passThrough[myfaces._impl.core.Impl._PROP_EXECUTE].length > 0) {
+            arguments['partialIdsArray'] = passThrough[myfaces._impl.core.Impl._PROP_EXECUTE].split(" ");
+        }
+        return arguments;
+    },
+
+    /**
+     * helper method to apply a config setting to our varargs param list
+     *
+     * @param destination the destination map to receive the setting
+     * @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) {
+        var _Runtime = myfaces._impl.core._Runtime;
+        var _getConfig = _Runtime.getLocalOrGlobalConfig;
+        if (_getConfig(this._context, srcParm, null) != null) {
+            destination[destParm] = _getConfig(this._context, srcParm, null);
+        }
+    },
+
+    /**
+     * standard on done handler which routes to the
+     * event sending specified by the spec
+     *
+     * @param request the xhr request object
+     * @param context the context holding all values for further processing
+     */
+    _stdOnDone: function(request, context) {
+        var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
+
+        _Impl.sendEvent(request, context, _Impl._AJAX_STAGE_COMPLETE);
+    },
+
+    /**
+     * standard spec compliant success handler
+     *
+     * @param request the xhr request object
+     * @param context the context holding all values for further processing
+     */
+    _stdOnSuccess: function(request, context) {
+        //_onSuccess
+        var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
+
+        _Impl.response(request, context);
+        _Impl.sendEvent(request, context, _Impl._AJAX_STAGE_SUCCESS);
+        this._queue.processQueue();
+
+    },
+
+    /**
+     * now to the error case handlers which by spec should
+     * route to our standard error queue
+     *
+     * @param request the xhr request object
+     * @param context the context holding all values for further processing
+     */
+    _stdOnError: function(request, context) {
+        var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
+        
+        //_onError
+        var errorText;
+        try {
+            errorText = "Request failed";
+            if (request.status) {
+                errorText += "with status " + request.status;
+                if (request.statusText) {
+                    errorText += " and reason " + this._xhr.statusText;
+                }
+            }
+        } catch (e) {
+            errorText = "Request failed with unknown status";
+        }
+        //_onError
+        _Impl.sendError(request, context, myfaces._impl.core.Impl._ERROR_HTTPERROR,
+                myfaces._impl.core.Impl._ERROR_HTTPERROR, errorText);
+    },
+
+
+
+    /**
+     * standard timeout handler
+     *
+     * @param request the xhr request object
+     * @param context the context holding all values for further processing
+     */
+    _stdOnTimeout: function(request, context) {
+        var timeoutFunc = _Lang.hitch(this,
+                function() {
+                    this._queue._curReq.abort();
+                });
+    },
+
+    /**
+     * Client error handlers which also in the long run route into our error queue
+     * but also are able to deliver more meaningful messages
+     *
+     *
+     * @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
+     */
+    _stdErrorHandler: function(request, context, sourceClass, func, exception) {
+        var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
+        if (this._threshold == "ERROR") {
+            _Impl.sendError(request, context, _Impl._ERROR_CLIENT_ERROR, exception.name,
+                    "MyFaces ERROR:" + this._Lang.createErrorMessage(sourceClass, func, exception));
+        }
+        this._queue.clear();
+        //we forward the exception, just in case so that the client
+        //will receive it in any way
+        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) {
+        var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
+
+        if (this._threshold == "WARNING" || this._threshold == "ERROR") {
+            _Impl.sendError(request, context, _Impl._ERROR_CLIENT_ERROR, exception.name,
+                    "MyFaces WARNING:" + this._Lang.createErrorMessage(sourceClass, func, exception));
+        }
+        this.destroy();
+    }
+
+});