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 2009/02/06 12:15:20 UTC

svn commit: r741534 - in /myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces: _util/_Logger.js _util/_TrRequestQueue.js _util/_TrinidadFrameworkAdapter.js ajax/jsf.js

Author: werpu
Date: Fri Feb  6 11:15:19 2009
New Revision: 741534

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

ongoing works on the compatibility to the ri, introduced a framework adapter which will allow to replace the xhr engine in the long run!


Added:
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrinidadFrameworkAdapter.js
Modified:
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_Logger.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrRequestQueue.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_Logger.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_Logger.js?rev=741534&r1=741533&r2=741534&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_Logger.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_Logger.js Fri Feb  6 11:15:19 2009
@@ -1,19 +1,3 @@
-/*
- *  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.
- *  under the License.
- */
-
-
 /**
  * Generical simplified browser independend logger
  * on browsers which offer a console object
@@ -53,6 +37,12 @@
     myfaces._Logger.prototype.LOG_LEVEL_INFO     = 5;
     myfaces._Logger.prototype.LOG_LEVEL_OFF      = 6;
 
+    /*global logging configuration*/
+    myfaces._Logger.LOG_CONSOLE     = true;
+    myfaces._Logger.LOG_DIV         = true;
+    myfaces._Logger.LOG_DOCUMENT    = true;
+    myfaces._Logger.LOG_ALERT       = false;
+
     myfaces._Logger.getInstance = function(targetDiv) {
         var retVal = null;
         var targetDivId = null;
@@ -86,45 +76,51 @@
         this._targetDiv = targetDiv;/*null or a valid element*/
     };
 
-    myfaces._Logger.prototype.debug = function(/*Object*/varArgs/*,...*/) {
-        if(this._logLevel > this.LOG_LEVEL_DEBUG) return;
-
+    /**
+     * main logging algorithm
+     * we either root into the console
+     * or into the dom
+     * or into the document
+     * or into alerts depending on whehther one or the other
+     * exists and the configuration!
+     */
+    myfaces._Logger.prototype._logIt = function(/*String*/logType,/*caller arguments*/ varArgs) {
+        //TODO map the caller...
         if(this._hasConsole) {
-            console.debug(varArgs)
+            if(myfaces._Logger.LOG_CONSOLE) {
+                //TODO find out how to reference the proper line number etc...
+                console[logType.toLowerCase()](myfaces._JSF2Utils.arrayToString( varArgs ));
+            }
         } else if(null != this._targetDiv) {
-            this._targetDiv.innerHTML = this._targetDiv.innerHTML + "<br /> [DEBUG] : "+ myfaces._JSF2Utils.arrayToString(arguments, " ");
+            if(myfaces._Logger.LOG_DIV) {
+                this._targetDiv.innerHTML = this._targetDiv.innerHTML + "<br /> ["+logType+"] : "+ myfaces._JSF2Utils.arrayToString(varArgs, " ");
+            }
         } else { /*in case a target fails we use document.write*/
-            document.write("<br /> [DEBUG] : " + myfaces._JSF2Utils.arrayToString(arguments, " "));
+            if(myfaces._Logger.LOG_DOCUMENT) {
+                document.write("<br /> ["+logType+"] : " + myfaces._JSF2Utils.arrayToString(varArgs, " "));
+            }
+            if(myfaces._Logger.LOG_ALERT) {
+                alert("<br /> ["+logType+"] : " + myfaces._JSF2Utils.arrayToString(varArgs, " "));
+            }
+
         }
+    }
+
+    myfaces._Logger.prototype.debug = function(/*Object*/varArgs/*,...*/) {
+        if(this._logLevel > this.LOG_LEVEL_DEBUG) return;
+
+        this._logIt("DEBUG", arguments);
     };
     myfaces._Logger.prototype.error = function(varArgs/*,...*/) {
         if(this._logLevel > this.LOG_LEVEL_ERROR) return;
-        if(this._hasConsole) {
-            console.error(varArgs)
-        } else if(null != this._targetDiv) {
-            this._targetDiv.innerHTML = this._targetDiv.innerHTML + "<br /> [ERROR] : " + myfaces._JSF2Utils.arrayToString(arguments, " ");
-        } else { /*in case a target fails we use document.write*/
-            document.write("<br /> [ERROR] : "+ myfaces._JSF2Utils.arrayToString(arguments, " "));
-        }
+        this._logIt("ERROR", arguments);
     };
     myfaces._Logger.prototype.warn = function(varArgs/*,...*/) {
         if(this._logLevel > this.LOG_LEVEL_WARN) return;
-        if(this._hasConsole) {
-            console.warn(varArgs)
-        } else if(null != this._targetDiv) {
-            this._targetDiv.innerHTML = this._targetDiv.innerHTML + "<br /> [WARN] : " + myfaces._JSF2Utils.arrayToString(arguments, " ");
-        } else { /*in case a target fails we use document.write*/
-            document.write("<br /> [WARN] : "+ myfaces._JSF2Utils.arrayToString(arguments, " "));
-        }
+        this._logIt("WARN", arguments);
     };
     myfaces._Logger.prototype.info = function(/*Object*/varArgs/*,...*/) {
         if(this._logLevel > this.LOG_LEVEL_WARN) return;
-        if(this._hasConsole) {
-            console.info(varArgs)
-        } else if(null != this._targetDiv) {
-            this._targetDiv.innerHTML = this._targetDiv.innerHTML + "<br /> [INFO] : "+ myfaces._JSF2Utils.arrayToString(arguments, " ");
-        } else { /*in case a target fails we use document.write*/
-            document.write("<br /> [INFO] : "+ myfaces._JSF2Utils.arrayToString(arguments, " "));
-        }
+        this._logIt("INFO", arguments);
     };
 }
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrRequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrRequestQueue.js?rev=741534&r1=741533&r2=741534&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrRequestQueue.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrRequestQueue.js Fri Feb  6 11:15:19 2009
@@ -178,7 +178,7 @@
     {
        return myfaces._JSF2Utils.getPostbackContent(actionForm, params)
     }
-   
+
     //
     // Generic API
     //
@@ -399,7 +399,7 @@
         catch(e)
         {
             myfaces._TrRequestQueue._alertError();
-            myfaces._TrRequestQueue._logError("Error while performing request", e);
+            myfaces._TrRequestQueue._logError("myfaces._TrRequestQueue.prototype._handleIFrameLoad ", "Error while performing request", e);
             this._htmlForm.action = this._savedActionUrl;
             this._htmlForm.target = this._savedTarget;
         }
@@ -449,8 +449,9 @@
         }
         if ((statusCode != 200) && (statusCode != 0))
         {
+            //TODO check if the alert here is still needed?
             myfaces._TrRequestQueue._alertError();
-            myfaces._TrRequestQueue._logError("Error StatusCode(",
+            myfaces._TrRequestQueue._logError("myfaces._TrRequestQueue.prototype._handleRequestCallback","Error StatusCode(",
                     statusCode,
                     ") while performing request\n",
                     xmlHttp.getResponseText());
@@ -579,7 +580,7 @@
                 }
                 catch (e)
                 {
-                    myfaces._TrRequestQueue._logError("Error on DTS State Change Listener", e);
+                    myfaces._TrRequestQueue._logError("myfaces._TrRequestQueue.prototype._broadcastStateChangeEvent","Error on DTS State Change Listener", e);
                 }
             }
         }
@@ -603,11 +604,11 @@
     // Logging helper for use in Firebug
     myfaces._TrRequestQueue._logWarning = function(varArgs)
     {
-       myfaces._JSF2Utils.logWarning(varArgs);
+       myfaces._JSF2Utils.logWarning(arguments);
     }
     // Logging helper for use in Firebug
     myfaces._TrRequestQueue._logError = function(varArgs)
     {
-         myfaces._JSF2Utils.logError(varArgs);
+         myfaces._JSF2Utils.logError(arguments);
     }
 }
\ No newline at end of file

Added: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrinidadFrameworkAdapter.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrinidadFrameworkAdapter.js?rev=741534&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrinidadFrameworkAdapter.js (added)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/_util/_TrinidadFrameworkAdapter.js Fri Feb  6 11:15:19 2009
@@ -0,0 +1,98 @@
+/**
+ * Generic Trinidad Transport framework adapter so that we
+ * can plug other adapters in
+ *
+ * Every adapter has to follow
+ * a certain interface can can call back into jsf and jsf.ajax as long
+ * as no recursive calls are done!
+ *
+ * every framework adapter has to implement .sendRequest = function(ajaxContext,  action, viewState, passThroughArguments )
+ * and can trigger into sendEvent and ajaxResponse of the jsf.ajax function
+ *
+ */
+
+_reserveMyfaces();
+if (!myfaces._JSF2Utils.exists(myfaces, "_TrinidadFrameworkAdapter")) {
+    myfaces._TrinidadFrameworkAdapter = function() {
+        this._delegate = new myfaces._TrRequestQueue();
+    };
+
+    /**
+     * central request callback
+     */
+    myfaces._TrinidadFrameworkAdapter.prototype.sendRequest = function(ajaxContext,  action, viewState, passThroughArguments ) {
+        this._delegate.sendRequest(ajaxContext, this._trXhrCallback, action, viewState+"&"+myfaces._JSF2Utils.getPostbackContentFromMap(passThroughArguments));
+    };
+
+
+    /**
+     * Maps an internal Trinidad xmlhttprequest event
+     * into one compatible with the events of the ri
+     * this is done for compatibility purposes
+     * since trinidad follows similar rules regarding
+     * the events we just have to map the eventing accordingly
+     *
+     * note I am implementing this after reading the ri code
+     *
+     */
+    myfaces._TrinidadFrameworkAdapter.prototype._mapTrinidadToRIEvents = function(/*object*/ xhrContext,/*_TrXMLRequestEvent*/ event) {
+        var complete = false;
+
+        switch(event.getStatus()) {
+            //TODO add mapping code here
+            case myfaces._TrXMLRequestEvent.STATUS_QUEUED:
+                break; /*we have to wait*/
+            case myfaces._TrXMLRequestEvent.STATUS_SEND_BEFORE:
+                jsf.ajax.sendEvent(null, xhrContext, jsf.ajax._AJAX_STAGE_BEGIN)
+                break;;
+            case myfaces._TrXMLRequestEvent.STATUS_SEND_AFTER:
+                /*still waiting, we can add listeners later if it is allowed*/
+                break;
+            case myfaces._TrXMLRequestEvent.STATUS_COMPLETE:
+                /**
+            *here we can do our needed callbacks so
+            *that the specification is satisfied
+            **/
+                complete = true;
+                var responseStatusCode = event.getResponseStatusCode();
+                if(200 <= responseStatusCode && 300 > responseStatusCode ) {
+                    jsf.ajax.sendEvent(event.getRequest(), xhrContext, jsf.ajax._AJAX_STAGE_COMPLETE);
+                } else {
+                    jsf.ajax.sendEvent(event.getRequest(), xhrContext, jsf.ajax._AJAX_STAGE_COMPLETE);
+                    jsf.ajax.sendError(event.getRequest(), xhrContext, jsf.ajax._AJAX_STAGE_HTTPERROR);
+                }
+                break;
+            default:
+                break;
+        }
+        return complete;
+    };
+
+    /**
+ * Internal Trinidad
+ * JSF 2.0 callback compatibility handler
+ * since we use trinidad as our transport we have to do it that way
+ *
+ * this function switches the context via the
+ * xhr bindings
+ * it is now under the context of
+ * given by the calling function
+ */
+    myfaces._TrinidadFrameworkAdapter.prototype._trXhrCallback = function(/*_TrXMLRequestEvent*/ event) {
+        var context = this;//remapping is done by the trinidad engine
+        /**
+         *generally every callback into this method must issue an event
+         *we do a static call because we have lost our scope
+         *another way would be to reassign the function to the context
+         *which might be possible but I have to check the ri for that
+         */
+        var complete = myfaces._TrinidadFrameworkAdapter.prototype._mapTrinidadToRIEvents(context, event);
+
+        /**
+         * the standard incoming events are handled appropriately we now can deal with the response
+         */
+        if(complete) {
+            jsf.ajax.response(event.getRequest(), context);
+        }
+    }
+}
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js?rev=741534&r1=741533&r2=741534&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js Fri Feb  6 11:15:19 2009
@@ -62,7 +62,7 @@
 jsf.ajax._AJAX_STAGE_HTTPERROR = "httpError";
 
 /*Event queues*/
-jsf.ajax._requestQueue = new myfaces._TrRequestQueue();
+jsf.ajax._xhrAdapter = new myfaces._TrinidadFrameworkAdapter();
 
 /**
  * external event listener queue!
@@ -115,8 +115,6 @@
      **/
     var JSF2Utils   = myfaces._JSF2Utils;
 
-
-
     /**
      * assert element
      */
@@ -293,7 +291,7 @@
     /**
      * we now use the trinidad request queue to send down the ajax request
      */
-    JSFAjax._requestQueue.sendRequest(ajaxContext, JSFAjax._trXhrCallback, sourceForm.action, viewState+"&"+JSF2Utils.getPostbackContentFromMap(passThroughArguments) );
+    JSFAjax._xhrAdapter.sendRequest(ajaxContext, sourceForm.action, viewState, passThroughArguments);
 
 /*
      * TODO #61
@@ -364,87 +362,20 @@
 
 
 
-/**
- * Maps an internal Trinidad xmlhttprequest event
- * into one compatible with the events of the ri
- * this is done for compatibility purposes
- * since trinidad follows similar rules regarding
- * the events we just have to map the eventing accordingly
- *
- * note I am implementing this after reading the ri code
- *
- */
-jsf.ajax._mapTrinidadToRIEvents = function(/*object*/ xhrContext,/*_TrXMLRequestEvent*/ event) {
-    var complete = false;
-
-    switch(event.getStatus()) {
-        //TODO add mapping code here
-        case myfaces._TrXMLRequestEvent.STATUS_QUEUED:
-            break; /*we have to wait*/
-        case myfaces._TrXMLRequestEvent.STATUS_SEND_BEFORE:
-            jsf.ajax.sendEvent(null, xhrContext, jsf.ajax._AJAX_STAGE_BEGIN)
-            break;;
-        case myfaces._TrXMLRequestEvent.STATUS_SEND_AFTER:
-            /*still waiting, we can add listeners later if it is allowed*/
-            break;
-        case myfaces._TrXMLRequestEvent.STATUS_COMPLETE:
-            /**
-            *here we can do our needed callbacks so
-            *that the specification is satisfied
-            **/
-            complete = true;
-            var responseStatusCode = event.getResponseStatusCode();
-            if(200 <= responseStatusCode && 300 > responseStatusCode ) {
-                jsf.ajax.sendEvent(event.getRequest(), xhrContext, jsf.ajax._AJAX_STAGE_COMPLETE);
-            } else {
-                jsf.ajax.sendEvent(event.getRequest(), xhrContext, jsf.ajax._AJAX_STAGE_COMPLETE);
-                jsf.ajax.sendError(event.getRequest(), xhrContext, jsf.ajax._AJAX_STAGE_HTTPERROR);
-            }
-            break;
-        default:
-            break;
-    }
-    return complete;
-};
-
-/**
- * Internal Trinidad
- * JSF 2.0 callback compatibility handler
- * since we use trinidad as our transport we have to do it that way
- *
- * this function switches the context via the
- * xhr bindings
- * it is now under the context of
- * given by the calling function
- */
-jsf.ajax._trXhrCallback = function(/*_TrXMLRequestEvent*/ event) {
-    var context = {};
-    /*to ease readability we switch the transferred context
-     *params back into a real context map*/
-    context.onerror = this.onerror;
-    context.onevent = this.onevent;
-    context.source = this.source;
-
-    /**
-     *generally every callback into this method must issue an event
-     */
-    var complete = jsf.ajax._mapTrinidadToRIEvents(context, event);
 
-    /**
-     * the standard incoming events are handled appropriately we now can deal with the response
-     */
-    if(complete) {
-        jsf.ajax.ajaxResponse(event.getRequest());
-    }
-}
 /**
  * processes the ajax response if the ajax request completes successfully
  * @param request the ajax request!
  */
-jsf.ajax.ajaxResponse = function(/*xhr request object*/request) {
+jsf.ajax.response = function(/*xhr request object*/request, context) {
     if ('undefined' == typeof(request) || null == request) {
         throw Exception("jsf.ajaxResponse: The response cannot be null or empty!");
     }
+
+    if(!myfaces._JSF2Utils.exists(request, "responseXML")) {
+        jsf.ajax.sendError(request, context, "emptyResponse");
+        return;
+    }
 //TODO handle the ppr part here
 //check the specs on the format of the return xml to do the ppr as expected!
 
@@ -473,6 +404,3 @@
      */
     return this._projectStage;
 };
-
-
-