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/10 11:53:46 UTC

svn commit: r942699 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/_HtmlStripper.js _util/_LangUtils.js _util/_Utils.js core/jsf_impl.js xhrCore/_AjaxRequest.js xhrCore/_AjaxResponse.js xhrCore/_AjaxUtils.js

Author: werpu
Date: Mon May 10 09:53:46 2010
New Revision: 942699

URL: http://svn.apache.org/viewvc?rev=942699&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2707
https://issues.apache.org/jira/browse/MYFACES-2700
https://issues.apache.org/jira/browse/MYFACES-2706




Modified:
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_LangUtils.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js?rev=942699&r1=942698&r2=942699&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js Mon May 10 09:53:46 2010
@@ -43,6 +43,9 @@
  * for instance comments with embedded head and body sections
  * or javascripts with head and body in strings..
  *
+ * Also we do not rely on the response being xhtml due to
+ * the fact that we might still have to cover jsp over html 4.0.1
+ *
  * We tried to solve that that way in the first place but due to
  * the nature of things a minimal semantic understanding in the parsing
  * process is needed to strip everything out correctly which is not entirely

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_LangUtils.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_LangUtils.js?rev=942699&r1=942698&r2=942699&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_LangUtils.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_LangUtils.js Mon May 10 09:53:46 2010
@@ -56,7 +56,7 @@ if ('undefined' == typeof _reserveMyface
 
     };
     _reserveMyfacesNamespaces();
-};
+}
 
 /**
  * Central internal JSF2 LangUtils with code used
@@ -68,7 +68,7 @@ if ('undefined' == typeof _reserveMyface
  */
 if ('undefined' == typeof(myfaces._impl._util._LangUtils) || null == myfaces._impl._util._LangUtils) {
     myfaces._impl._util._LangUtils = function() {
-    }
+    };
 
     myfaces._impl._util._LangUtils.global = this;
 
@@ -123,8 +123,8 @@ if ('undefined' == typeof(myfaces._impl.
 
     /**
      * Helper function to provide a trim with a given splitter regular expression
-     * @param {string} it the string to be trimmed
-     * @param {regexp} splitter the splitter regular expressiion
+     * @param {|String|} it the string to be trimmed
+     * @param {|RegExp|} splitter the splitter regular expressiion
      *
      * FIXME is this still used?
      */
@@ -181,7 +181,7 @@ if ('undefined' == typeof(myfaces._impl.
      * Backported from dojo
      * a failsafe string determination method
      * (since in javascript String != "" typeof alone fails!)
-     * @param it {anything} the object to be checked for being a string
+     * @param it {|anything|} the object to be checked for being a string
      * @return true in case of being a string false otherwiseÊ
      */
     myfaces._impl._util._LangUtils.isString = function(/*anything*/ it) {
@@ -231,7 +231,9 @@ if ('undefined' == typeof(myfaces._impl.
             scope = null;
         }
         if (this.isString(method)) {
-            scope = scope || window || function() {};/*since we do not have dojo global*/
+            scope = scope || window || function() {
+            };
+            /*since we do not have dojo global*/
             if (!scope[method]) {
                 throw(['myfaces._impl._util._LangUtils: scope["', method, '"] is null (scope="', scope, '")'].join(''));
             }
@@ -243,41 +245,30 @@ if ('undefined' == typeof(myfaces._impl.
             return method.apply(scope, arguments || []);
         }; // Function
     };
-    /**
-     * used internally to lazy init the logger
-     * Lazy init for the logging subsystem
-     * @deprecated will be removed soon
-     */
-    myfaces._impl._util._LangUtils._getLogger = function() {
-        if (null == myfaces._impl._util._LangUtils._logger) {
-            myfaces._impl._util._LangUtils._logger = myfaces._impl._util._Logger.getInstance();
-        }
-        return myfaces._impl._util._LangUtils._logger;
-    };
 
     myfaces._impl._util._LangUtils._hitchArgs = function(scope, method /*,...*/) {
         var pre = this._toArray(arguments, 2);
         var named = this.isString(method);
         return function() {
-            // arrayify arguments
+            // array-fy arguments
             var args = this._toArray(arguments);
             // locate our method
             var f = named ? (scope || myfaces._impl._util._LangUtils.global)[method] : method;
             // invoke with collected args
             return f && f.apply(scope || this, pre.concat(args)); // mixed
-        } // Function
+        }; // Function
     };
 
     /**
      * Helper function to merge two maps
      * into one
-     * @param {Map}Êdestination the destination map
-     * @param {Map}Êsource the source map
-     * @param {boolean} overwriteDest if set to true the destination is overwritten if the keys exist in both maps
+     * @param {|Object|} destination the destination map
+     * @param {|Object|} source the source map
+     * @param {|boolean|} overwriteDest if set to true the destination is overwritten if the keys exist in both maps
      **/
     myfaces._impl._util._LangUtils.mixMaps = function(destination, source, overwriteDest) {
         /**
-         * mixin code depending on the state of dest and the overwrite param
+         * mixing code depending on the state of dest and the overwrite param
          */
         var _JSF2Utils = myfaces._impl._util._LangUtils;
         var result = {};
@@ -313,7 +304,7 @@ if ('undefined' == typeof(myfaces._impl.
      */
     myfaces._impl._util._LangUtils.exists = function(root, element) {
         return ('undefined' != typeof root && null != root && 'undefined' != typeof root[element] && null != root[element]);
-    }
+    };
 
     /**
      * checks if an array contains an element
@@ -332,12 +323,12 @@ if ('undefined' == typeof(myfaces._impl.
     /**
      * Concatenates an array to a string
      * @param {Array} arr the array to be concatenated
-     * @param {String} delimiter, the concateation delimiter if none is set \n is used
+     * @param {String} delimiter the concatenation delimiter if none is set \n is used
      *
      * @return the concatenated array, one special behavior to enable j4fry compatibility has been added
      * if no delimiter is used the [entryNumber]+entry is generated for a single entry
      * TODO check if this is still needed it is somewhat outside of the scope of the function
-     * and functionalitywise dirty
+     * and functionality wise dirty
      */
     myfaces._impl._util._LangUtils.arrayToString = function(/*String or array*/ arr, /*string*/ delimiter) {
         if (myfaces._impl._util._LangUtils.isString(arr)) {
@@ -356,4 +347,149 @@ if ('undefined' == typeof(myfaces._impl.
         return resultArr.join(finalDelimiter);
     };
 
+
+    /**
+     * reserves a namespace in the specific scope
+     *
+     * usage:
+     * if(myfaces._impl._util._Lang.reserve("org.apache.myfaces.MyUtils")) {
+     *      org.apache.myfaces.MyUtils = function() {
+     *      }
+     * }
+     *
+     * reserves a namespace and if the namespace is new the function itself is reserved
+     *
+     *
+     *
+     * or:
+     * myfaces._impl._util._Lang.reserve("org.apache.myfaces.MyUtils", function() { ... });
+     *
+     * reserves a namespace and if not already registered directly applies the function the namespace
+     *
+     * @param {|String|} nameSpace
+     * @returns true if it was not provided
+     * false otherwise for further action
+     */
+
+    myfaces._impl._util._LangUtils.fetchNamespace = function(nameSpace) {
+        try {
+            return myfaces._impl._util._Utils.globalEval("window." + nameSpace);
+        } catch (e) {/*wanted*/
+        }
+        return null;
+    };
+
+    myfaces._impl._util._LangUtils.reserveNamespace = function(nameSpace, reservationFunction) {
+        var _Lang = myfaces._impl._util._LangUtils;
+        if (!_Lang.isString(nameSpace)) {
+            throw Error("Namespace must be a string with . as delimiter");
+        }
+        if (null != _Lang.fetchNamespace(nameSpace)) {
+            return false;
+        }
+
+        var namespaceEntries = nameSpace.split(/\./);
+        var currentNamespace = window;
+        for (var cnt = 0; cnt < namespaceEntries.length; cnt++) {
+            var subNamespace = namespaceEntries[cnt];
+            if ('undefined' == typeof currentNamespace[subNamespace]) {
+                currentNamespace[subNamespace] = {};
+            }
+            if (cnt == namespaceEntries.length - 1 && 'undefined' != typeof reservationFunction && null != reservationFunction) {
+                currentNamespace[subNamespace] = reservationFunction;
+            }
+            currentNamespace = currentNamespace[subNamespace];
+        }
+
+        return true;
+    };
+
+    /**
+     * prototype based delegation inheritance
+     *
+     * implements prototype delegaton inheritance dest <- a
+     *
+     * usage var newClass = myfaces._impl._util._LangUtils.extends(
+     * function (var1, var2) {
+     *  this.callSuper("constructor", var1,var2);
+     * };
+     * ,origClass);
+     * newClass.prototype.myMethod = function(arg1) {
+     *      this.callSuper("myMethod", arg1,"hello world");
+
+     other option
+     myfaces._impl._util._LangUtils.extends("myNamespace.newClass", parent, {
+        init: function() {constructor...},
+        method1: function(f1, f2) {},
+        method2: function(f1, f2,f3)
+
+     });
+
+
+     * I omit the dojo way here of passing entire function maps
+     * because in my experience they are hard to swallow for ides
+     * a simple extends should do it for now
+     * };
+     */
+
+    myfaces._impl._util._LangUtils.extendClass = function(newClass, extendsClass, functionMap) {
+        var _Lang = myfaces._impl._util._LangUtils;
+
+        if ('function' != typeof newClass) {
+
+
+            var constructor = null;
+            if ('undefined' != typeof functionMap && null != functionMap) {
+                constructor = ('undefined' != typeof null != functionMap['init'] && null != functionMap['init']) ? functionMap['init'] : function() {
+                };
+            } else {
+                constructor = function() {
+                };
+            }
+            if (!_Lang.reserveNamespace(newClass, constructor)) {
+                return null;
+            }
+            newClass = _Lang.fetchNamespace(newClass);
+        }
+
+        if (null != extendsClass) {
+            newClass.prototype = new extendsClass;
+            newClass.prototype.constructor = newClass;
+            newClass.prototype.parent = extendsClass.prototype;
+
+            newClass.prototype._callSuper = function(methodName) {
+                var passThrough = (arguments.length == 1) ? [] : Array.prototype.slice.call(arguments, 1);
+                this.parent[methodName].apply(this, passThrough);
+            };
+        }
+
+        //we now map the function map in
+        if ('undefined' != typeof functionMap && null != functionMap) {
+            for (var key in functionMap) {
+                newClass.prototype[key] = functionMap[key];
+                //we also can apply a direct _inherited method if the method overwrites an existing one
+                //http://ejohn.org/blog/simple-javascript-inheritance/ i don not eliminate it multiple calls to super
+                //can happen, this is the way dojo does it
+                
+                if (null != extendsClass && 'function' == typeof newClass.prototype.parent[key]) {
+                    //we now aop a decorator function on top of everything,
+                    //to make sure we have super set while it is executing
+                    var assignedFunction = newClass.prototype[key];
+                    var superFunction = newClass.prototype.parent[key];
+                    newClass.prototype[key] = function() {
+                        var oldSuper = newClass.prototype["_inherited"];
+                        newClass.prototype["_inherited"] = function() {
+                            this.parent[key].apply(this, arguments);
+                        }
+                        try {
+                            return assignedFunction.apply(this, arguments);
+                        } finally {
+                            newClass.prototype["_inherited"] = oldSuper;
+                        }
+                    }
+                }
+            }
+        }
+        return newClass;
+    };
 }

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js?rev=942699&r1=942698&r2=942699&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js Mon May 10 09:53:46 2010
@@ -20,12 +20,19 @@
 
 _reserveMyfacesNamespaces();
 
+/**
+ * TODO rename this utils class
+ * into DomUtils
+ * and move the functions not fitting here
+ * into LangUtils
+ *
+ */
 if (!myfaces._impl._util._LangUtils.exists(myfaces._impl._util, "_Utils")) {
     /**
      * Constructor
      */
     myfaces._impl._util._Utils = function() {
-    }
+    };
 
     myfaces._impl._util._Utils.browserDetection = function() {
         /**
@@ -36,7 +43,7 @@ if (!myfaces._impl._util._LangUtils.exis
          * hence we port it over it allows a very fine grained detection of
          * browsers including the version number
          * this however only can work out if the user
-         * does not alter the user agend, which they normally dont!
+         * does not alter the user agent, which they normally dont!
          *
          * the exception is the ie detection which relies on specific quirks in ie
          */
@@ -94,7 +101,7 @@ if (!myfaces._impl._util._LangUtils.exis
 
     /**
      * encapsulated xhr object which tracks down various implementations
-     * of the xhr object in a browser independend fashion
+     * of the xhr object in a browser independent fashion
      * (ie pre 7 used to have non standard implementations because
      * the xhr object standard came after IE had implemented it first
      * newer ie versions adhere to the standard and all other new browsers do anyway)
@@ -110,7 +117,7 @@ if (!myfaces._impl._util._LangUtils.exis
 
         }
         return new ActiveXObject('Microsoft.XMLHTTP');
-    }
+    };
 
     /**
      * [STATIC]
@@ -149,7 +156,7 @@ if (!myfaces._impl._util._LangUtils.exis
         } else {
             throw Error("Loading of script " + src + " failed ");
         }
-    }
+    };
 
     /**
      * [STATIC]
@@ -160,8 +167,8 @@ if (!myfaces._impl._util._LangUtils.exis
      * @param {HtmlElement} item
      */
     myfaces._impl._util._Utils.runScripts = function(request, context, item) {
-        if (item.nodeType == 1) { // only if it's an element node
-            if (item.tagName.toLowerCase() == 'script') {
+        if (item.nodeType == 1) { // only if it's an element node or document fragment
+            if ('undefined' != typeof item.tagName && item.tagName.toLowerCase() == 'script') {
                 try {
                     if (typeof item.getAttribute('src') != 'undefined'
                             && item.getAttribute('src') != null
@@ -201,7 +208,7 @@ if (!myfaces._impl._util._LangUtils.exis
                 }
             }
         }
-    }
+    };
 
     /**
      * Simple delete on an existing item
@@ -215,7 +222,7 @@ if (!myfaces._impl._util._LangUtils.exis
         }
 
         item.parentNode.removeChild(item);
-    }
+    };
 
     /**
      * [STATIC]
@@ -228,21 +235,26 @@ if (!myfaces._impl._util._LangUtils.exis
      */
     myfaces._impl._util._Utils.replaceHtmlItem = function(request, context, itemIdToReplace, newTag, form) {
         try {
+
+            //TODO handle multiple eval nodes here
+
             //for webkit we have to trim otherwise he does not add the adjancent elements correctly
             newTag = myfaces._impl._util._LangUtils.trim(newTag);
 
             // (itemIdToReplace instanceof Node) is NOT compatible with IE8
             var item = (typeof itemIdToReplace == "object") ? itemIdToReplace :
-                       myfaces._impl._util._Utils.getElementFromForm(request, context, itemIdToReplace, form);
+                    myfaces._impl._util._Utils.getElementFromForm(request, context, itemIdToReplace, form);
 
             if (item == null) {
                 myfaces._impl.xhrCore._Exception.throwNewWarning
                         (request, context, "Utils", "replaceHTMLItem", "Unknown Html-Component-ID: " + itemIdToReplace);
-                return;
+                return null;
             }
 
             if (newTag != "") {
                 var evalNode = null;
+
+                //w3c compliant browsers with proper contextual fragments
                 if (typeof window.Range != 'undefined'
                         && typeof Range.prototype.createContextualFragment == 'function') {
                     var range = document.createRange();
@@ -252,30 +264,36 @@ if (!myfaces._impl._util._LangUtils.exis
                     //with the first element (the place holder is the the only child)
                     //and then append additional elements as additional childs
                     //the body itself then is the root for the eval part!
-                    if(item.id == 'myfaces_bodyplaceholder') {
+                    if (item.id == 'myfaces_bodyplaceholder') {
                         var parentNode = item.parentNode;
                         parentNode.appendChild(fragment);
                         evalNode = parentNode;
                     } else {
                         //normal dom node case we replace only the client id fragment!
-                        //TODO this code is heavily under discussion, probably invalid in the long run
-                        //I am reverting the findHtmlItemFromFragment back to fragment
-                        //var replaceItem = myfaces._impl._util._Utils.findHtmlItemFromFragment(fragment, item.id);
-                        //if(replaceItem == null)replaceItem = fragment;
-                        // replaceItem = fragment;
-                        evalNode = item.parentNode.replaceChild(fragment, item);
+
+                        var parentNode = item.parentNode;
+
+                        evalNode = fragment.childNodes[0];
+                        parentNode.replaceChild(fragment, item);
                     }
                 } else {
-                    item.insertAdjacentHTML('beforeBegin', newTag);
-                    evalNode = item.previousSibling;
-                    item.parentNode.removeChild(item);
-                    if(item.id != 'myfaces_bodyplaceholder' && ('undefined' == typeof evalNode.id  || null == evalNode.id || evalNode.id != item.id)) {
-                        //to get the same behavior (as in other browsers we have to cherry pick the element differently here)
-                        //black box testing on Mojarra reveals, it does nothing here, and breaks the page this way
-                        var subNode = document.getElementById(item.id);
-                        subNode.parentNode.removeChild(subNode);
-                        evalNode.parentNode.replaceChild(subNode, evalNode);
-                    }
+
+                    //now to the non w3c compliant browsers
+                    //http://blogs.perl.org/users/clinton_gormley/2010/02/forcing-ie-to-accept-script-tags-in-innerhtml.html
+                    var dummyPlaceHolder = document.createElement("div");
+
+                    //fortunately a table element also works which is less critical than form elements regarding
+                    //the inner content
+                    dummyPlaceHolder.innerHTML = "<table>" + newTag + "</table>";
+                    evalNode = dummyPlaceHolder.childNodes[0].childNodes[0].childNodes[0];
+                    var parentNode = item.parentNode;
+                    item.parentNode.replaceChild(evalNode, item);
+
+                    //if this as well will fail in the future, we can let ie parse a proper xml
+                    //extract the script elements and then create the script elements manually
+                    //but for now we will not need it, and this solution is faster
+                    //the downside of that solution would be that the fragment itself
+                    //must resolve to a valid xml
                 }
 
                 // and remove the old item
@@ -283,7 +301,7 @@ if (!myfaces._impl._util._LangUtils.exis
                 if (myfaces._impl._util._Utils.isManualScriptEval()) {
                     myfaces._impl._util._Utils.runScripts(request, context, evalNode);
                 }
-                return;
+                return evalNode;
             }
             // and remove the old item, in case of an empty newtag and do nothing else
             item.parentNode.removeChild(item);
@@ -291,34 +309,104 @@ if (!myfaces._impl._util._LangUtils.exis
         } catch (e) {
             myfaces._impl.xhrCore._Exception.throwNewError(request, context, "Utils", "replaceHTMLItem", e);
         }
+        return null;
     };
 
+    /**
+     * finds a corresponding html item from a given identifier and
+     * dom fragment
+     * @param fragment the dom fragment to find the item for
+     * @param itemId the identifier of the item
+     */
     myfaces._impl._util._Utils.findHtmlItemFromFragment = function(fragment, itemId) {
-        if (fragment.childNodes == null)
-            return null;
-        //normal usecase, some browsers behave saner in complex situations if we work directly
-        //on the fragment, since the recommended path from the eg is to use an outer element
-        //having the id, this is the normal usecase
-        if(fragment.childNodes.length == 1 && fragment.childNodes[0].id == itemId) {
+        //TODO add iterator handlers here for browsers which allow dom filters and iterators
+
+        if ('undefined' != typeof fragment.id && fragment.id === itemId) {
             return fragment;
         }
 
-        //subfragment usecases
-        for (var i = 0; i < fragment.childNodes.length; i++) {
-            var c = fragment.childNodes[i];
-            if (c.id == itemId)
-                return c;
-        }
-        for (var i = 0; i < fragment.childNodes.length; i++) {
-            var c = fragment.childNodes[i];
-            var item = myfaces._impl._util._Utils.findHtmlItemFromFragment(c, itemId);
+        if (fragment.childNodes == null)
+            return null;
+
+        //sub-fragment usecases
+        var child;
+        var cnt;
+        for (cnt = 0; cnt < fragment.childNodes.length; cnt++) {
+            child = fragment.childNodes[cnt];
+            if ('undefined' != typeof fragment.id && child.id === itemId)
+                return child;
+        }
+        for (cnt = 0; cnt < fragment.childNodes.length; cnt++) {
+            child = fragment.childNodes[cnt];
+            var item = myfaces._impl._util._Utils.findHtmlItemFromFragment(child, itemId);
             if (item != null)
                 return item;
         }
         return null;
     };
 
-    myfaces._impl._util._Utils.ieQuircksEvents = {
+    /**
+     * determines the number of nodes according to their tagType
+     *
+     * @param {NodeFragment} fragment the fragment to be investigated
+     * @param {String}ÊtagName the tag name (lowercase)
+     * @param {Boolean}ÊdeepScan if set to true a found element does not prevent to scan deeper
+     * (the normal usecase is false, which means if the element is found only its
+     * adjacent elements will be scanned, due to the recursive descension
+     * this should work out with elements with different nesting depths but not being
+     * parent and child to each other
+     */
+    myfaces._impl._util._Utils.findHtmlTypeFromFragment = function(fragment, tagName, deepScan) {
+        var retVal = [];
+        //TODO add iterator handlers here for browsers which allow dom filters and iterators
+
+        if ('undefined' != typeof fragment.tagName && fragment.tagName.toLowerCase() === tagName) {
+            retVal.push(fragment);
+            if (!deepScan) return retVal;
+        }
+
+        if ('undefined' == typeof fragment.childNodes || fragment.childNodes == null)
+            return retVal;
+
+        //subfragment usecases
+        var cnt;
+        var childNode;
+        for (cnt = 0; cnt < fragment.childNodes.length; cnt++) {
+            childNode = fragment.childNodes[cnt];
+            if ('undefined' != typeof childNode.tagName && childNode.tagName.toLowerCase() === tagName)
+                retVal.push(childNode);
+        }
+
+        for (cnt = 0; (deepScan || retVal.length == 0) && cnt < fragment.childNodes.length; cnt++) {
+            childNode = fragment.childNodes[cnt];
+            var subRetVals = myfaces._impl._util._Utils.findHtmlTypeFromFragment(childNode, tagName);
+            retVal = retVal.concat(subRetVals);
+        }
+        return retVal;
+
+    };
+
+    /**
+     *
+     * @param {Node} form
+     * @param {String}ÊnameOrIdenitifier
+     *
+     * checks for a a element with the name or identifier of nameOrIdentifier
+     * @returns the found node or null otherwise
+     */
+    myfaces._impl._util._Utils.findFormElement = function(form, nameOrIdenitifier) {
+        var eLen = form.elements.length;
+        //TODO add iterator handlers here for browsers which allow dom filters and iterators
+
+        for (var e = 0; e < eLen; e++) {
+            var elem = form.elements[e];
+            if ('undefined' != typeof elem.name && elem.name === nameOrIdenitifier) return elem;
+            if ('undefined' != typeof elem.id && elem.id === nameOrIdenitifier) return elem;
+        } // end of for (formElements)
+        return null;
+    };
+
+    myfaces._impl._util._Utils._ieQuircksEvents = {
         "onabort": true,
         "onload":true,
         "onunload":true,
@@ -401,10 +489,10 @@ if (!myfaces._impl._util._LangUtils.exis
             //check if the attribute is an event, since this applies only
             //to quirks mode of ie anyway we can live with the standard html4/xhtml
             //ie supported events
-            if (myfaces._impl._util._Utils.ieQuircksEvents[attribute]) {
+            if (myfaces._impl._util._Utils._ieQuircksEvents[attribute]) {
                 if (myfaces._impl._util._LangUtils.isString(attribute)) {
                     domNode.setAttribute(attribute, function(event) {
-                        myfaces._impl._util._Utils.globalEval(attribute);
+                        return eval(value);
                     });
                 }
             } else {
@@ -427,20 +515,20 @@ if (!myfaces._impl._util._LangUtils.exis
         //
         //tested currently safari, ie, firefox, opera
         var retVal = (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isIE") &&
-                      ( myfaces._impl._util._Utils.browser.isIE > 5.5)) ||
-                     (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isKhtml") &&
-                      (myfaces._impl._util._Utils.browser.isKhtml > 0)) ||
-                     (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isWebKit") &&
-                      (myfaces._impl._util._Utils.browser.isWebKit > 0)) ||
-                     (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isSafari") &&
-                      (myfaces._impl._util._Utils.browser.isSafari > 0));
+                ( myfaces._impl._util._Utils.browser.isIE > 5.5)) ||
+                (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isKhtml") &&
+                        (myfaces._impl._util._Utils.browser.isKhtml > 0)) ||
+                (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isWebKit") &&
+                        (myfaces._impl._util._Utils.browser.isWebKit > 0)) ||
+                (_LangUtils.exists(myfaces._impl._util._Utils.browser, "isSafari") &&
+                        (myfaces._impl._util._Utils.browser.isSafari > 0));
 
         return retVal;
 
         //another way to determine this without direct user agent parsing probably could
         //be to add an embedded script tag programmatically and check for the script variable
         //set by the script if existing, the add went through an eval if not then we
-        //have to deal with it outselves, this might be dangerous in case of the ie however
+        //have to deal with it ourselves, this might be dangerous in case of the ie however
         //so in case of ie we have to parse for all other browsers we can make a dynamic
         //check if the browser does auto eval
         //TODO discuss those things
@@ -557,8 +645,7 @@ if (!myfaces._impl._util._LangUtils.exis
         var submitName = ('undefined' != element.name) ? element.name : null;
         //a framework in a detachment case also can replace an existing identifier element
         // with a name element
-        submitName = (null == submitName) ? submitIdentifier: submitName;
-
+        submitName = (null == submitName) ? submitIdentifier : submitName;
 
         if ('undefined' != typeof submitIdentifier && null != submitIdentifier && '' != submitIdentifier) {
             //we have to assert that the element passed down is detached
@@ -593,7 +680,6 @@ if (!myfaces._impl._util._LangUtils.exis
             return null;
         }
 
-
         return foundElements[0];
     };
 
@@ -654,7 +740,7 @@ if (!myfaces._impl._util._LangUtils.exis
             }
         }
         return null;
-    }
+    };
 
     /**
      * fetches a global config entry
@@ -684,24 +770,22 @@ if (!myfaces._impl._util._LangUtils.exis
         if (myfaces._impl._util._Utils.browser.isIE && window.execScript) {
             //execScript definitely only for IE otherwise we might have a custom
             //window extension with undefined behavior on our necks
-            window.execScript(code);
-            return;
+            return window.execScript(code);
+
         } else if (undefined != typeof (window.eval) && null != window.eval) {
 
-            //fix for a Mozilla bug, a bug, Mozilla prevents, that the window is properly applied
-            //the former approach was to scope an outer anonymouse function but the scoping is not necessary
+            //fix for a Mozilla bug, Mozilla prevents, that the window is properly applied
+            //the former approach was to scope an outer anonymous function but the scoping is not necessary
             //Mozilla behaves correctly if you just add an outer function, then the window scope is again
             //accepted as the real scope
             var func = function () {
-                window.eval.call(window, code);
+                return window.eval.call(window, code);
             };
-            func();
-
-            return;
+            return func();
         }
         //we probably have covered all browsers, but this is a safety net which might be triggered
         //by some foreign browser which is not covered by the above cases
-        eval.call(window, code);
+        return eval.call(window, code);
     };
 
     /**
@@ -727,6 +811,15 @@ if (!myfaces._impl._util._LangUtils.exis
     };
 
     /**
+     * Convenience method
+     * to fetch the implementation from
+     * our lazily binding configuration system
+     */
+    myfaces._impl._util._Utils.getImpl = function() {
+        myfaces._impl._util._Utils.getGlobalConfig("jsfAjaxImpl", myfaces.ajax);
+    };
+
+    /**
      * concatenation routine which concats all childnodes of a node which
      * contains a set of CDATA blocks to one big string
      * @param {Node} node the node to concat its blocks for

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js?rev=942699&r1=942698&r2=942699&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js Mon May 10 09:53:46 2010
@@ -74,7 +74,7 @@ if (!myfaces._impl._util._LangUtils.exis
      * find the javax.faces.ViewState element and encode its value as well!
      * return a concatenated string of the encoded values!
      *
-     * @throws an exception in case of the given element not being of type form!
+     * @throws exception in case of the given element not being of type form!
      * https://issues.apache.org/jira/browse/MYFACES-2110
      */
     myfaces._impl.core._jsfImpl.prototype.getViewState = function(formElement) {
@@ -135,7 +135,7 @@ if (!myfaces._impl._util._LangUtils.exis
         if (!(func instanceof Function)) {
             throw new Error("Functioncall " + func + " is not a function! ");
         }
-    }
+    };
 
     /**
      * this function has to send the ajax requests
@@ -282,18 +282,18 @@ if (!myfaces._impl._util._LangUtils.exis
     myfaces._impl.core._jsfImpl.prototype.addOnError = function(/*function*/errorListener) {
         /*error handling already done in the assert of the queue*/
         this._errorListenerQueue.add(errorListener);
-    }
+    };
 
     myfaces._impl.core._jsfImpl.prototype.addOnEvent = function(/*function*/eventListener) {
         /*error handling already done in the assert of the queue*/
         this._eventListenerQueue.add(eventListener);
-    }
+    };
 
     /**
      * implementation triggering the error chain
      *
      * @param {Object} request the request object which comes from the xhr cycle
-     * @param {Map} context the context object being pushed over the xhr cycle keeping additional metadata �
+     * @param {Map} context the context object being pushed over the xhr cycle keeping additional metadata
      * @param {String} name, the error name
      * @param {String} serverErrorName the server error name in case of a server error
      * @param {String} serverErrorMessage the server error message in case of a server error
@@ -302,7 +302,7 @@ if (!myfaces._impl._util._LangUtils.exis
      *  the registered error handlers in the queue receiv an error message to be dealt with
      *  and if the projectStage is at development an alert box is displayed
      *
-     *  note: we have additonal functionality here, via the global config myfaces.config.defaultErrorOutput a function can be provieded
+     *  note: we have additional functionality here, via the global config myfaces.config.defaultErrorOutput a function can be provided
      *  which changes the default output behavior from alert to something else
      *
      *
@@ -361,7 +361,8 @@ if (!myfaces._impl._util._LangUtils.exis
                 eventData.responseText = request.responseText;
                 eventData.responseCode = request.status;
             } catch (e) {
-                myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, "ErrorRetrievingResponse",
+                var impl = myfaces._impl._util._Utils.getGlobalConfig("jsfAjaxImpl", myfaces.ajax);
+                impl.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, "ErrorRetrievingResponse",
                         "Parts of the response couldn't be retrieved when constructing the event data: " + e);
                 //client errors are not swallowed 
                 throw e;
@@ -491,31 +492,6 @@ if (!myfaces._impl._util._LangUtils.exis
             //but we reuse the argument array capabilities of apply
             var retVal;
 
-            /*
-             * Ok I have revisited this part again, the black boxed ri test reveals:
-             *
-             <h:outputScript name = "jsf.js" library = "javax.faces" target = "head" />
-             <script type="text/javascript">
-             function pressMe(event) {
-             alert(this);
-             return true;
-             }
-             function chainMe(origin, event) {
-             jsf.util.chain(origin, event, "alert('hello world'); return true;", pressMe);
-             }
-
-             </script>
-
-             <div onclick="chainMe(this, event);">
-             press me
-             </div>
-
-             that the RI can only handle stringed scripts we can handle functions and scripts
-             I will contact the members of the EG on what the correct behavior is
-             *
-             * Arbitrary code block in my opinon means that we have to deal with both functions
-             * and evaled strings
-             */
             if ('function' == typeof arguments[loop]) {
                  retVal = arguments[loop].call(thisVal, event);
             } else {

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=942699&r1=942698&r2=942699&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 10 09:53:46 2010
@@ -82,6 +82,8 @@ if (!myfaces._impl._util._LangUtils.exis
      */
     myfaces._impl.xhrCore._AjaxRequest.prototype.send = function() {
         try {
+            var ajaxRequestQueue =  myfaces._impl.xhrCore._AjaxRequestQueue.queue;
+
             this.m_xhr = myfaces._impl._util._Utils.getXHRObject();
             
             this.m_xhr.open("POST", this.m_sourceForm.action, true);
@@ -95,9 +97,9 @@ if (!myfaces._impl._util._LangUtils.exis
 	            var timeoutId = window.setTimeout(
 	            	function() {
 	            		try {
-		            		if ( myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.m_xhr.readyState > 0 
-		            		&& myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.m_xhr.readyState < 4) {
-		            			myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.m_xhr.abort();
+		            		if ( ajaxRequestQueue.m_request.m_xhr.readyState > 0
+		            		&& ajaxRequestQueue.queue.m_request.m_xhr.readyState < 4) {
+		            			ajaxRequestQueue.queue.m_request.m_xhr.abort();
 		            		}
 	            		} catch (e) {
 	            			// don't care about exceptions here
@@ -117,15 +119,17 @@ if (!myfaces._impl._util._LangUtils.exis
     myfaces._impl.xhrCore._AjaxRequest.prototype.requestCallback = function() {
         var READY_STATE_DONE = 4;
         try {
+            //local namespace remapping
+            var jsfAjaxImpl = myfaces.ajax;
 
             if (this.m_xhr.readyState == READY_STATE_DONE) {
                 if (this.m_xhr.status >= 200 && this.m_xhr.status < 300) {
-                	myfaces.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
-                	myfaces.ajax.response(this.m_xhr, this.m_context);
-                	myfaces.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_SUCCESS);
+                	jsfAjaxImpl.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
+                	jsfAjaxImpl.response(this.m_xhr, this.m_context);
+                	jsfAjaxImpl.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_SUCCESS);
                     myfaces._impl.xhrCore._AjaxRequestQueue.queue.processQueue();
                 } else {
-                	myfaces.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
+                	jsfAjaxImpl.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
             		var errorText;
                 	try {
                 		errorText = "Request failed";
@@ -138,7 +142,7 @@ if (!myfaces._impl._util._LangUtils.exis
                 	} catch (e) {
                 		errorText = "Request failed with unknown status";
                 	}
-                	myfaces.ajax.sendError(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._ERROR_HTTPERROR,
+                	jsfAjaxImpl.sendError(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._ERROR_HTTPERROR,
                         myfaces._impl.core._jsfImpl._ERROR_HTTPERROR, errorText);
                 }
             }

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=942699&r1=942698&r2=942699&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 10 09:53:46 2010
@@ -30,12 +30,16 @@ if (!myfaces._impl._util._LangUtils.exis
     myfaces._impl.xhrCore._AjaxResponse = function(alarmThreshold) {
         this.alarmThreshold = alarmThreshold;
         this.m_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*/
     myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSE_PARTIAL = "partial-response";
     myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_ERROR = "error";
     /*TODO: -=Leonardo Uribe=- Does this response type really exists? really from server comes a partial-response with redirect command*/
+    /*This really exists, it is for cases where a button issues a command and the server wants to redirect after processing the ajax request*/
     myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_REDIRECT = "redirect";
     myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_REDIRECT = "changes";
 
@@ -48,7 +52,7 @@ if (!myfaces._impl._util._LangUtils.exis
     myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_ERROR = "error";
     myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_ATTRIBUTES = "attributes";
     myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_EXTENSION = "extension";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_REDIRECT = "redirect"
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_REDIRECT = "redirect";
     /**
      * uses response to start Html element replacement
      *
@@ -124,11 +128,43 @@ if (!myfaces._impl._util._LangUtils.exis
                     if (!this.processChanges(request, context, childNode)) return;
                 }
             }
+            
+            //fixup missing viewStates due to spec deficiencies
+            this.fixViewStates();
         } catch (e) {
             this.m_exception.throwError(request, context, "processResponse", e);
         }
     };
 
+    myfaces._impl.xhrCore._AjaxResponse.prototype.fixViewStates = function() {
+        if(null == this.appliedViewState) {
+            return;
+        }
+        /*namespace remapping*/
+        var _Utils = myfaces._impl._util._Utils;
+
+        //note the spec here says clearly it is done, but mojarra not and there is a corner case
+        //regarding cross form submits, hence we should check all processed items for embedded forms
+        for (var cnt = 0; cnt < this.changeTrace.length; cnt ++) {
+            var replacementElem = this.changeTrace[cnt];
+            var replacedForms = myfaces._impl._util._Utils.findHtmlTypeFromFragment(replacementElem, "form", false);
+            for (var formCnt = 0; formCnt < replacedForms.length; formCnt++) {
+                //we first have to fetch the real form element because the fragment
+                //might be detached in some browser implementations
+                var appliedReplacedFrom = document.getElementById(replacedForms[formCnt].id);
+                var viewStateField = myfaces._impl._util._Utils.findFormElement(appliedReplacedFrom, "javax.faces.ViewState");
+                if (null == viewStateField) {
+                    var element = document.createElement("input");
+                    _Utils.setAttribute(element, "type", "hidden");
+                    _Utils.setAttribute(element, "name", "javax.faces.ViewState");
+                    appliedReplacedFrom.appendChild(element);
+
+                    _Utils.setAttribute(element, "value", this.appliedViewState);
+                }
+            }
+        }
+    };
+
     myfaces._impl.xhrCore._AjaxResponse.prototype.processError = function(request, context, node) {
         /**
          * <error>
@@ -146,7 +182,7 @@ if (!myfaces._impl._util._LangUtils.exis
             errorMessage = "";
         }
         myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_SERVER_ERROR, errorName, errorMessage);
-    }
+    };
 
     myfaces._impl.xhrCore._AjaxResponse.prototype.processRedirect = function(request, context, node) {
         /**
@@ -163,19 +199,24 @@ if (!myfaces._impl._util._LangUtils.exis
         }
         window.location = redirectUrl;
         return true;
-    }
+    };
 
     myfaces._impl.xhrCore._AjaxResponse.prototype.processChanges = function(request, context, node) {
+        
+        var _Utils = myfaces._impl._util._Utils;
+        
         var changes = node.childNodes;
 
+        //note we need to trace the changes which could affect our insert update or delete
+        //se that we can realign our ViewStates afterwards
+        //the realignment must happen post change processing
+
         for (var i = 0; i < changes.length; i++) {
             if (changes[i].tagName == "update") {
                 if (!this.processUpdate(request, context, changes[i])) return false;
             } else if (changes[i].tagName == this._PCMD_EVAL) {
                 //eval is always in CDATA blocks
-                //TODO split eval handling
-
-                myfaces._impl._util._Utils.globalEval(changes[i].firstChild.data);
+                _Utils.globalEval(changes[i].firstChild.data);
             } else if (changes[i].tagName == this._PCMD_INSERT) {
                 if (!this.processInsert(request, context, changes[i])) return false;
             } else if (changes[i].tagName == this._PCMD_DELETE) {
@@ -192,16 +233,21 @@ if (!myfaces._impl._util._LangUtils.exis
                 return false;
             }
         }
+        //second step we step over all updates which have identifiers to check whether there are lost
+        // viewStates
+
         return true;
-    }
+    };
 
     myfaces._impl.xhrCore._AjaxResponse.prototype.processUpdate = function(request, context, node) {
-        if (node.getAttribute('id') == "javax.faces.ViewState") {
+        /*local namespace remapping*/
+        var _Utils = myfaces._impl._util._Utils;
 
+        if (node.getAttribute('id') == "javax.faces.ViewState") {
             //update the submitting forms viewstate to the new value
             // The source form has to be pulled out of the CURRENT document first because the context object
             // may refer to an invalid document if an update of the entire body has occurred before this point.
-
+            var viewStateValue = node.firstChild.nodeValue;
             var sourceForm = myfaces._impl._util._Utils.fuzzyFormDetection(null, context, context.source);
 
             //the source form could be determined absolutely by either the form, the identifier of the node, or the name
@@ -211,16 +257,15 @@ if (!myfaces._impl._util._LangUtils.exis
                 var element = myfaces._impl._util._Utils.getElementFromForm(request, context, "javax.faces.ViewState", sourceForm, true, true);
                 if (null == element) {//no element found we have to append a hidden field
                     element = document.createElement("input");
-                    myfaces._impl._util._Utils.setAttribute(element, "type", "hidden");
-                    myfaces._impl._util._Utils.setAttribute(element, "name", "javax.faces.ViewState");
+                    _Utils.setAttribute(element, "type", "hidden");
+                    _Utils.setAttribute(element, "name", "javax.faces.ViewState");
                     sourceForm.appendChild(element);
                 }
                 //viewstate cannot have split cdata blocks so we can skip the costlier operation
-                myfaces._impl._util._Utils.setAttribute(element, "value", node.firstChild.nodeValue);
 
+                _Utils.setAttribute(element, "value", viewStateValue);
             }
-            //else??? the latest spec has this omitted we have to wait for the RI which probably covers this
-
+            this.appliedViewState = viewStateValue;
         } else {
             // response may contain several blocks
             var cDataBlock = myfaces._impl._util._Utils.concatCDATABlocks(node);
@@ -242,8 +287,10 @@ if (!myfaces._impl._util._LangUtils.exis
                     break;
 
                 default:
-                    this._replaceElement(request, context, node.getAttribute('id'), cDataBlock);
-
+                    var resultNode = this._replaceElement(request, context, node.getAttribute('id'), cDataBlock);
+                    if ('undefined' != typeof resultNode && null != resultNode) {
+                        this.changeTrace.push(resultNode);
+                    }
                     break;
             }
         }
@@ -261,6 +308,9 @@ if (!myfaces._impl._util._LangUtils.exis
      * @param {String} newData the markup which replaces the old dom node!
      */
     myfaces._impl.xhrCore._AjaxResponse.prototype._replaceBody = function(request, context, newData) {
+
+        var _Utils = myfaces._impl._util._Utils;
+
         var parser = myfaces.ajax._impl = new (myfaces._impl._util._Utils.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
 
         var oldBody = document.getElementsByTagName("body")[0];
@@ -273,13 +323,16 @@ if (!myfaces._impl._util._LangUtils.exis
 
         //the contextualFragment trick does not work on the body tag instead we have to generate a manual body
         //element and then add a child which then is the replacement holder for our fragment!
+
+        //TODO we probably should try to offload this to the browser first via the integrated xml parsing
+        //and if it fails revert to our internal parser
         var bodyData = parser.parse(newData, "body");
         bodyParent.replaceChild(newBody, oldBody);
         this._replaceElement(request, context, placeHolder, bodyData);
 
         for (var key in parser.tagAttributes) {
             var value = parser.tagAttributes[key];
-            myfaces._impl._util._Utils.setAttribute(newBody, key, value);
+            _Utils.setAttribute(newBody, key, value);
         }
     };
 
@@ -287,11 +340,11 @@ if (!myfaces._impl._util._LangUtils.exis
      * Helper method to avoid duplicate code
      * @param {Object} request our request object
      * @param {Map} context the response context
-     * @param {DomNode} oldElement the element to be replaced
+     * @param {DomNode} oldElement the element to be replaced
      * @param {String} newData the markup which replaces the old dom node!
      */
     myfaces._impl.xhrCore._AjaxResponse.prototype._replaceElement = function(request, context, oldElement, newData) {
-        myfaces._impl._util._Utils.replaceHtmlItem(request, context,
+        return myfaces._impl._util._Utils.replaceHtmlItem(request, context,
                 oldElement, newData, this.m_htmlFormElement);
     };
 
@@ -305,33 +358,40 @@ if (!myfaces._impl._util._LangUtils.exis
      * the after is the id if set which the component has to be inserted after
      **/
     myfaces._impl.xhrCore._AjaxResponse.prototype.processInsert = function(request, context, node) {
+
+        /*remapping global namespaces for speed and readability reasons*/
+        var _LangUtils = myfaces._impl._util._LangUtils;
+        var _Utils = myfaces._impl._util._Utils;
+        var _JSFImpl = myfaces._impl.core._jsfImpl;
+        
+        
         var insertId = node.getAttribute('id');
         var beforeId = node.getAttribute('before');
         var afterId = node.getAttribute('after');
 
-        var insertSet = 'undefined' != typeof insertId && null != insertId && myfaces._impl._util._LangUtils.trim(insertId) != "";
-        var beforeSet = 'undefined' != typeof beforeId && null != beforeId && myfaces._impl._util._LangUtils.trim(beforeId) != "";
-        var afterSet = 'undefined' != typeof afterId && null != afterId && myfaces._impl._util._LangUtils.trim(afterId) != "";
+        var insertSet = 'undefined' != typeof insertId && null != insertId && _LangUtils.trim(insertId) != "";
+        var beforeSet = 'undefined' != typeof beforeId && null != beforeId && _LangUtils.trim(beforeId) != "";
+        var afterSet = 'undefined' != typeof afterId && null != afterId &&_LangUtils.trim(afterId) != "";
 
         if (!insertSet) {
-            myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, id must be present");
+            myfaces.ajax.sendError(request, context, _JSFImpl._ERROR_MALFORMEDXML, _JSFImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, id must be present");
             return false;
         }
         if (!(beforeSet || afterSet)) {
-            myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, before id or after id must be present");
+            myfaces.ajax.sendError(request, context, _JSFImpl._ERROR_MALFORMEDXML, _JSFImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, before id or after id must be present");
             return false;
         }
         //either before or after but not two at the same time
         var nodeHolder = null;
         var parentNode = null;
 
-        var cDataBlock = myfaces._impl._util._Utils.concatCDATABlocks(node);
+        var cDataBlock = _Utils.concatCDATABlocks(node);
 
         if (beforeSet) {
-            beforeId = myfaces._impl._util._LangUtils.trim(beforeId);
+            beforeId =_LangUtils.trim(beforeId);
             var beforeNode = document.getElementById(beforeId);
             if ('undefined' == typeof beforeNode || null == beforeNode) {
-                myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, before  node of id " + beforeId + " does not exist in document");
+                myfaces.ajax.sendError(request, context, _JSFImpl._ERROR_MALFORMEDXML, _JSFImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, before  node of id " + beforeId + " does not exist in document");
                 return false;
             }
             /**
@@ -344,36 +404,49 @@ if (!myfaces._impl._util._LangUtils.exis
             parentNode = beforeNode.parentNode;
             parentNode.insertBefore(nodeHolder, beforeNode);
 
-            myfaces._impl._util._Utils.replaceHtmlItem(request, context,
+            var replacementFragment = _Utils.replaceHtmlItem(request, context,
                     nodeHolder, cDataBlock, null);
 
+            if ('undefined' != typeof replacementFragment && null != replacementFragment) {
+                this.changeTrace.push(replacementFragment);
+            }
+
         } else {
-            afterId = myfaces._impl._util._LangUtils.trim(afterId);
+            afterId =_LangUtils.trim(afterId);
             var afterNode = document.getElementById(afterId);
             if ('undefined' == typeof afterNode || null == afterNode) {
-                myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, after  node of id " + after + " does not exist in document");
+                myfaces.ajax.sendError(request, context, _JSFImpl._ERROR_MALFORMEDXML, _JSFImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, after  node of id " + after + " does not exist in document");
                 return false;
             }
+
             nodeHolder = document.createElement("div");
             parentNode = afterNode.parentNode;
             parentNode.insertBefore(nodeHolder, afterNode.nextSibling);
-            myfaces._impl._util._Utils.replaceHtmlItem(request, context,
+
+            var replacementFragment = _Utils.replaceHtmlItem(request, context,
                     nodeHolder, cDataBlock, null);
+
+            if ('undefined' != typeof replacementFragment && null != replacementFragment) {
+                this.changeTrace.push(replacementFragment);
+            }
+
         }
         return true;
-    }
+    };
 
     myfaces._impl.xhrCore._AjaxResponse.prototype.processDelete = function(request, context, node) {
+        var _JSFImpl =  myfaces._impl.core._jsfImpl;
+
         var deleteId = node.getAttribute('id');
         if ('undefined' == typeof deleteId || null == deleteId) {
-            myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,
-                    myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in delete, id not in xml markup");
+            myfaces.ajax.sendError(request, context, _JSFImpl._ERROR_MALFORMEDXML,
+                    _JSFImpl._ERROR_MALFORMEDXML, "Error in delete, id not in xml markup");
             return false;
         }
 
         myfaces._impl._util._Utils.deleteItem(request, context, deleteId, "", "");
         return true;
-    }
+    };
 
     myfaces._impl.xhrCore._AjaxResponse.prototype.processAttributes = function(request, context, node) {
         //we now route into our attributes function to bypass
@@ -382,12 +455,15 @@ if (!myfaces._impl._util._LangUtils.exis
         //behaves as usual not like the official standard
         //myfaces._impl._util._Utils.setAttribute(domNode, attribute, value;
 
+        var _Utils = myfaces._impl._util._Utils;
+        var _JSFImpl = myfaces._impl.core._jsfImpl;
+
         //<attributes id="id of element"> <attribute name="attribute name" value="attribute value" />* </attributes>
         var attributesRoot = node;
         var elementId = attributesRoot.getAttribute('id');
         if ('undefined' == typeof elementId || null == elementId) {
-            myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML
-                    , myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in attributes, id not in xml markup");
+            myfaces.ajax.sendError(request, context, _JSFImpl._ERROR_MALFORMEDXML
+                    , _JSFImpl._ERROR_MALFORMEDXML, "Error in attributes, id not in xml markup");
             return false;
         }
         var childs = attributesRoot.childNodes;
@@ -422,16 +498,16 @@ if (!myfaces._impl._util._LangUtils.exis
 
                 case "javax.faces.ViewHead":
                     var element = document.getElementsByTagName("body")[0];
-                    myfaces._impl._util._Utils.setAttribute(element, attributeName, attributeValue);
+                    _Utils.setAttribute(element, attributeName, attributeValue);
                     break;
 
                 default:
-                    myfaces._impl._util._Utils.setAttribute(document.getElementById(elementId), attributeName, attributeValue);
+                    _Utils.setAttribute(document.getElementById(elementId), attributeName, attributeValue);
                     break;
             }
 
         }
         return true;
-    }
+    };
 
 }

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=942699&r1=942698&r2=942699&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 10 09:53:46 2010
@@ -74,7 +74,6 @@ if (!myfaces._impl._util._LangUtils.exis
 
             return stringBuffer.join("");
         } catch (e) {
-            alert(e);
             this.m_exception.throwError(request, context, "processUserEntries", e);
         }
     };