myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gan...@apache.org
Subject svn commit: r780394 [2/2] - in /myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces: _impl/_util/ _impl/core/ _impl/xhrCore/ api/
Date Sun, 31 May 2009 09:32:20 GMT
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Sun May 31 09:32:13 2009
@@ -1,394 +1,394 @@
-/*
- * 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: werpu $)
- * Version: $Revision: 1.18 $ $Date: 2009/04/24 13:14:02 $
- *
- */
-
-_reserveMyfacesNamespaces();
-
-
-if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxResponse")) {
-
-
-    /**
-     * Constructor
-     * @param {String} alarmThreshold
-     */
-    myfaces._impl.xhrCore._AjaxResponse = function(alarmThreshold) {
-        this.alarmThreshold = alarmThreshold;
-        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxResponse", this.alarmThreshold);
-    };
-
-    /*partial response types*/
-    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSE_PARTIAL         = "partial-response";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_ERROR       = "error";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_REDIRECT    = "redirect";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_REDIRECT    = "changes";
-
-    /*partial commands*/
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_CHANGES     = "changes";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_UPDATE      = "update";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_DELETE      = "delete";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_INSERT      = "insert";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_EVAL        = "eval";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_ERROR       = "error";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_ATTRIBUTES  = "attributes";
-    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_EXTENSION   = "extension";
-
-    /**
-     * uses response to start Html element replacement
-     * @param {Map} context - AJAX context
-     *
-     * A special handling has to be added to the update cycle
-     * according to the JSDoc specs if the CDATA block contains html tags the outer rim must be stripped
-     * if the CDATA block contains a head section the document head must be replaced
-     * and if the CDATA block contains a body section the document body must be replaced!
-     *
-     */
-    myfaces._impl.xhrCore._AjaxResponse.prototype.processResponse = function(request, context) {
-        try {
-            // TODO:
-            // Solution from
-            // http://www.codingforums.com/archive/index.php/t-47018.html
-            // to solve IE error 1072896658 when a Java server sends iso88591
-            // istead of ISO-8859-1
-            if ('undefined' == typeof(request) || null == request) {
-                throw Exception("jsf.ajaxResponse: The response cannot be null or empty!");
-            }
-
-            if (!myfaces._impl._util._LangUtils.exists(request, "responseXML")) {
-                jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_EMPTY_RESPONSE);
-                return;
-            }
-
-            var xmlContent = request.responseXML;
-            if (xmlContent.firstChild.tagName == "parsererror") {
-                jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML);
-                return;
-            }
-            var partials = xmlContent.childNodes[0];
-            if ('undefined' == typeof partials || partials == null
-                || partials.tagName != this._RESPONSE_PARTIAL) {
-                jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML);
-                return;
-            }
-
-            var childNodesLength = partials.childNodes.length;
-
-            for (var loop = 0; loop < childNodesLength; loop++) {
-                var childNode = partials.childNodes[loop];
-                var tagName = childNode.tagName;
-
-                /**
-                 * <eval>
-                 *      <![CDATA[javascript]]>
-                 * </eval>
-                 */
-
-            
-
-                //this ought to be enough for eval
-                //however the run scripts still makes sense
-                //in the update and insert area for components
-                //which do not use the response writer properly
-                //we might add this one as custom option in update and
-                //insert!
-                if (tagName == this._PCMD_ERROR) {
-                    this.processError(request, context, childNode);
-                    return;
-                } else if (tagName == this._PCMD_REDIRECT) {
-                    if (!this.processRedirect(request, context, childNode)) return;
-                } else if (tagName == this._PCMD_CHANGES) {
-                    if (!this.processChanges(request, context, childNode)) return;
-                }
-            }
-        } catch (e) {
-            this.m_exception.throwError(request, context, "processResponse", e);
-        }
-    };
-
-    myfaces._impl.xhrCore._AjaxResponse.prototype.processError = function(request, context, node) {
-        /**
-     * <error>
-     *      <error-name>String</error-name>
-     *      <error-message><![CDATA[message]]></error-message>
-     * <error>
-     */
-        var errorName = node.firstChild.textContent;
-        var errorMessage = node.childNodes[1].firstChild.data;
-
-        if('undefined' == typeof errorName || null == errorName) {
-            errorName = "";
-        }
-        if('undefined' == typeof errorMessage || null == errorMessage) {
-            errorMessage = "";
-        }
-        jsf.ajax.sendError(request, context,myfaces._impl.core._jsfImpl._ERROR_SERVER_ERROR , errorName, errorMessage);
-    }
-
-    myfaces._impl.xhrCore._AjaxResponse.prototype.processRedirect = function(request, context, node) {
-        /**
-     * <redirect url="url to redirect" />
-     */
-        var redirectUrl = node.getAttribute("url");
-        if('undefined' == typeof redirectUrl || null == redirectUrl) {
-            jsf.ajax.sendError(request, context,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,"Redirect without url");
-            return false;
-        }
-        redirectUrl = myfaces._impl._util._LangUtils.trim(redirectUrl);
-        if(redirectUrl == "") {
-            return false;
-        }
-        window.location = redirectUrl;
-        return true;
-    }
-
-    myfaces._impl.xhrCore._AjaxResponse.prototype.processChanges = function(request, context, node) {
-        var changes = node.childNodes;
-
-        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
-                myfaces._impl._util._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) {
-                if (!this.processDelete(request, context, changes[i])) return false;
-            } else if (changes[i].tagName == this._PCMD_ATTRIBUTES) {
-                if (!this.processAttributes(request, context, changes[i])) return false;
-            // this._responseHandler.doAtttributes(childNode);
-            //TODO check the spec if this part is obsolete!!!
-            //} else if (changes[i].tagName == this._PCMD_EXTENSION) {
-            //  this._responseHandler.doExtension(childNode);
-
-            } else {
-                jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML);
-                return false;
-            }
-        }
-        return true;
-    }
-
-    myfaces._impl.xhrCore._AjaxResponse.prototype.processUpdate = function(request, context, node) {
-        if (node.getAttribute('id') == "javax.faces.ViewState") {
-            /*if(null != document.getElementById("javax.faces.ViewState")) {
-                document.getElementById("javax.faces.ViewState").value = node.firstChild.nodeValue;
-            } else {
-
-            }*/
-            //update the submitting forms viewstate to the new value
-
-            var sourceForm = myfaces._impl._util._Utils.getParent(null, context, context.source, "form");
-
-            if ('undefined' == typeof sourceForm || null == sourceForm) {
-                sourceForm = document.forms.length > 0 ? document.forms[0]:null;
-            }
-            if(null != sourceForm) {
-                /*we check for an element and include a namesearch, but only within the bounds of the committing form*/
-                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");
-                    sourceForm.appendChild(element);
-                }
-                myfaces._impl._util._Utils.setAttribute(element,"value", node.firstChild.nodeValue);
-
-            }
-            //else??? the latest spec has this omitted we have to wait for the RI which probably covers this
-
-        } else {
-            var cDataBlock = [];
-            // response may contain sevaral blocks
-            for (var i = 0; i < node.childNodes.length; i++) {
-                cDataBlock.push( node.childNodes[i].data);
-            }
-            //a join is more efficient that normal string ops!
-            cDataBlock = cDataBlock.join("");
-
-            var body = document.getElementsByTagName('body')[0];
-            var head = document.getElementsByTagName('head')[0];
-
-            switch(node.getAttribute('id')) {
-                case "javax.faces.ViewRoot":
-
-                    var parser =  jsf.ajax._impl = new (myfaces._impl._util._Utils.getGlobalConfig("updateParser",myfaces._impl._util._HtmlStripper))();
-                
-                    document.documentElement.innerHTML  =  parser.parse(cDataBlock);
-                        // innerHTML doesn't execute scripts, so no browser switch here
-                    myfaces._impl._util._Utils.runScripts(request, context, cDataBlock);
-                   
-                    break;
-                case "javax.faces.ViewHead":
-                    //we assume the cdata block is our head including the tag
-                    this._replaceElement(request, context, head, cDataBlock );
-                    
-
-                    break;
-                case "javax.faces.ViewBody":
-                    //we assume the cdata block is our body including the tag
-                    this._replaceElement(request, context, body, cDataBlock );
-  
-                    break;
-
-                default:
-                    this._replaceElement(request, context,node.getAttribute('id'), cDataBlock );
-                   
-                    break;
-            }
-        }
-        return true;
-    };
-
-    /**
-     * Helper method to avoid duplicate code
-     * @param request our request object
-     * @param contect the response context
-     * @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,
-            oldElement, newData, this.m_htmlFormElement);
-        //fetch the scripts and do an eval on the scripts to bypass
-        //browser inconsistencies in this area
-        //lets have the browser itself deal with this issue, j4fry
-        //is pretty well optimized in this area!
-        if (myfaces._impl._util._Utils.isManualScriptEval()) {
-            myfaces._impl._util._Utils.runScripts(request, context, newData);
-        }
-    };
-
-    /*insert, three attributes can be present
-     * id = insert id
-     * before = before id
-     * after = after  id
-     *
-     * the insert id is the id of the node to be inserted
-     * the before is the id if set which the component has to be inserted before
-     * 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) {
-        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) != "";
-
-        if(!insertSet) {
-            jsf.ajax.sendError(request, context,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML, "Error in PPR Insert, id must be present");
-            return false;
-        }
-        if(!(beforeSet || afterSet)) {
-            jsf.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");
-            return false;
-        }
-        //either before or after but not two at the same time
-        if(beforeSet) {
-            beforeId = myfaces._impl._util._LangUtils.trim(beforeId);
-            var beforeNode = document.getElementById(beforeId);
-            if('undefined' == typeof beforeNode || null == beforeNode) {
-                jsf.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");
-                return false;
-            }
-            /**
-             *we generate a temp holder
-             *so that we can use innerHTML for
-             *generating the content upfront
-             *before inserting it"
-             **/
-            var nodeHolder = document.createElement("div");
-            var parentNode = beforeNode.parentNode;
-            parentNode.insertBefore(nodeHolder, beforeNode);
-
-            myfaces._impl._util._Utils.replaceHtmlItem(request, context,
-                nodeHolder, node.firstChild.data, null);
-
-        } else {
-            afterId = myfaces._impl._util._LangUtils.trim(afterId);
-            var afterNode = document.getElementById(afterId);
-            if('undefined' == typeof afterNode || null == afterNode) {
-                jsf.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");
-                return false;
-            }
-            var nodeHolder = document.createElement("div");
-            var parentNode = afterNode.parentNode;
-            parentNode.insertBefore(nodeHolder, afterNode.nextSibling);
-            myfaces._impl._util._Utils.replaceHtmlItem(request, context,
-                nodeHolder, node.firstChild.data, null);
-        }
-        return true;
-    }
-
-    myfaces._impl.xhrCore._AjaxResponse.prototype.processDelete = function(request, context, node) {
-        var deleteId = node.getAttribute('id');
-        if('undefined' == typeof deleteId || null == deleteId) {
-            jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,
-                myfaces._impl.core._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
-        //IE quirks mode incompatibilities to the biggest possible extent
-        //most browsers just have to do a setAttributes but IE
-        //behaves as usual not like the official standard
-        //myfaces._impl._util._Utils.setAttribute(domNode, attribute, value;
-
-        //<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) {
-            jsf.ajax.sendError(request, context,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML
-                ,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,  "Error in attributes, id not in xml markup");
-            return false;
-        }
-        var childs = attributesRoot.childNodes;
-
-        if('undefined' == typeof childs || null == childs) {
-            return false;
-        }
-        for(var loop2 = 0; loop2 < childs.length; loop2++) {
-            var attributesNode = childs[loop2];
-
-            var attributeName = attributesNode.getAttribute("name");
-            var attributeValue = attributesNode.getAttribute("value");
-
-            if('undefined' == typeof attributeName || null == attributeName) {
-                continue;
-            }
-
-            attributeName = myfaces._impl._util._LangUtils.trim(attributeName);
-            /*no value means reset*/
-            if('undefined' == typeof attributeValue || null == attributeValue) {
-                attributeValue = "";
-            }
-
-            myfaces._impl._util._Utils.setAttribute(document.getElementById(elementId), attributeName, attributeValue);
-        }
-        return true;
-    }
-
+/*
+ * 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.2 $ $Date: 2009/05/30 17:54:57 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+
+if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxResponse")) {
+
+
+    /**
+     * Constructor
+     * @param {String} alarmThreshold
+     */
+    myfaces._impl.xhrCore._AjaxResponse = function(alarmThreshold) {
+        this.alarmThreshold = alarmThreshold;
+        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxResponse", this.alarmThreshold);
+    };
+
+    /*partial response types*/
+    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSE_PARTIAL         = "partial-response";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_ERROR       = "error";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_REDIRECT    = "redirect";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._RESPONSETYPE_REDIRECT    = "changes";
+
+    /*partial commands*/
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_CHANGES     = "changes";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_UPDATE      = "update";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_DELETE      = "delete";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_INSERT      = "insert";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_EVAL        = "eval";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_ERROR       = "error";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_ATTRIBUTES  = "attributes";
+    myfaces._impl.xhrCore._AjaxResponse.prototype._PCMD_EXTENSION   = "extension";
+
+    /**
+     * uses response to start Html element replacement
+     * @param {Map} context - AJAX context
+     *
+     * A special handling has to be added to the update cycle
+     * according to the JSDoc specs if the CDATA block contains html tags the outer rim must be stripped
+     * if the CDATA block contains a head section the document head must be replaced
+     * and if the CDATA block contains a body section the document body must be replaced!
+     *
+     */
+    myfaces._impl.xhrCore._AjaxResponse.prototype.processResponse = function(request, context) {
+        try {
+            // TODO:
+            // Solution from
+            // http://www.codingforums.com/archive/index.php/t-47018.html
+            // to solve IE error 1072896658 when a Java server sends iso88591
+            // istead of ISO-8859-1
+            if ('undefined' == typeof(request) || null == request) {
+                throw Exception("jsf.ajaxResponse: The response cannot be null or empty!");
+            }
+
+            if (!myfaces._impl._util._LangUtils.exists(request, "responseXML")) {
+            	myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_EMPTY_RESPONSE);
+                return;
+            }
+
+            var xmlContent = request.responseXML;
+            if (xmlContent.firstChild.tagName == "parsererror") {
+            	myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML);
+                return;
+            }
+            var partials = xmlContent.childNodes[0];
+            if ('undefined' == typeof partials || partials == null
+                || partials.tagName != this._RESPONSE_PARTIAL) {
+            	myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML);
+                return;
+            }
+
+            var childNodesLength = partials.childNodes.length;
+
+            for (var loop = 0; loop < childNodesLength; loop++) {
+                var childNode = partials.childNodes[loop];
+                var tagName = childNode.tagName;
+
+                /**
+                 * <eval>
+                 *      <![CDATA[javascript]]>
+                 * </eval>
+                 */
+
+            
+
+                //this ought to be enough for eval
+                //however the run scripts still makes sense
+                //in the update and insert area for components
+                //which do not use the response writer properly
+                //we might add this one as custom option in update and
+                //insert!
+                if (tagName == this._PCMD_ERROR) {
+                    this.processError(request, context, childNode);
+                    return;
+                } else if (tagName == this._PCMD_REDIRECT) {
+                    if (!this.processRedirect(request, context, childNode)) return;
+                } else if (tagName == this._PCMD_CHANGES) {
+                    if (!this.processChanges(request, context, childNode)) return;
+                }
+            }
+        } catch (e) {
+            this.m_exception.throwError(request, context, "processResponse", e);
+        }
+    };
+
+    myfaces._impl.xhrCore._AjaxResponse.prototype.processError = function(request, context, node) {
+        /**
+     * <error>
+     *      <error-name>String</error-name>
+     *      <error-message><![CDATA[message]]></error-message>
+     * <error>
+     */
+        var errorName = node.firstChild.textContent;
+        var errorMessage = node.childNodes[1].firstChild.data;
+
+        if('undefined' == typeof errorName || null == errorName) {
+            errorName = "";
+        }
+        if('undefined' == typeof errorMessage || null == errorMessage) {
+            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) {
+        /**
+     * <redirect url="url to redirect" />
+     */
+        var redirectUrl = node.getAttribute("url");
+        if('undefined' == typeof redirectUrl || null == redirectUrl) {
+        	myfaces.ajax.sendError(request, context,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML,"Redirect without url");
+            return false;
+        }
+        redirectUrl = myfaces._impl._util._LangUtils.trim(redirectUrl);
+        if(redirectUrl == "") {
+            return false;
+        }
+        window.location = redirectUrl;
+        return true;
+    }
+
+    myfaces._impl.xhrCore._AjaxResponse.prototype.processChanges = function(request, context, node) {
+        var changes = node.childNodes;
+
+        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
+                myfaces._impl._util._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) {
+                if (!this.processDelete(request, context, changes[i])) return false;
+            } else if (changes[i].tagName == this._PCMD_ATTRIBUTES) {
+                if (!this.processAttributes(request, context, changes[i])) return false;
+            // this._responseHandler.doAtttributes(childNode);
+            //TODO check the spec if this part is obsolete!!!
+            //} else if (changes[i].tagName == this._PCMD_EXTENSION) {
+            //  this._responseHandler.doExtension(childNode);
+
+            } else {
+            	myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_MALFORMEDXML);
+                return false;
+            }
+        }
+        return true;
+    }
+
+    myfaces._impl.xhrCore._AjaxResponse.prototype.processUpdate = function(request, context, node) {
+        if (node.getAttribute('id') == "javax.faces.ViewState") {
+            /*if(null != document.getElementById("javax.faces.ViewState")) {
+                document.getElementById("javax.faces.ViewState").value = node.firstChild.nodeValue;
+            } else {
+
+            }*/
+            //update the submitting forms viewstate to the new value
+
+            var sourceForm = myfaces._impl._util._Utils.getParent(null, context, context.source, "form");
+
+            if ('undefined' == typeof sourceForm || null == sourceForm) {
+                sourceForm = document.forms.length > 0 ? document.forms[0]:null;
+            }
+            if(null != sourceForm) {
+                /*we check for an element and include a namesearch, but only within the bounds of the committing form*/
+                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");
+                    sourceForm.appendChild(element);
+                }
+                myfaces._impl._util._Utils.setAttribute(element,"value", node.firstChild.nodeValue);
+
+            }
+            //else??? the latest spec has this omitted we have to wait for the RI which probably covers this
+
+        } else {
+            var cDataBlock = [];
+            // response may contain sevaral blocks
+            for (var i = 0; i < node.childNodes.length; i++) {
+                cDataBlock.push( node.childNodes[i].data);
+            }
+            //a join is more efficient that normal string ops!
+            cDataBlock = cDataBlock.join("");
+
+            var body = document.getElementsByTagName('body')[0];
+            var head = document.getElementsByTagName('head')[0];
+
+            switch(node.getAttribute('id')) {
+                case "javax.faces.ViewRoot":
+
+                    var parser =  myfaces.ajax._impl = new (myfaces._impl._util._Utils.getGlobalConfig("updateParser",myfaces._impl._util._HtmlStripper))();
+                
+                    document.documentElement.innerHTML  =  parser.parse(cDataBlock);
+                        // innerHTML doesn't execute scripts, so no browser switch here
+                    myfaces._impl._util._Utils.runScripts(request, context, cDataBlock);
+                   
+                    break;
+                case "javax.faces.ViewHead":
+                    //we assume the cdata block is our head including the tag
+                    this._replaceElement(request, context, head, cDataBlock );
+                    
+
+                    break;
+                case "javax.faces.ViewBody":
+                    //we assume the cdata block is our body including the tag
+                    this._replaceElement(request, context, body, cDataBlock );
+  
+                    break;
+
+                default:
+                    this._replaceElement(request, context,node.getAttribute('id'), cDataBlock );
+                   
+                    break;
+            }
+        }
+        return true;
+    };
+
+    /**
+     * Helper method to avoid duplicate code
+     * @param request our request object
+     * @param contect the response context
+     * @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,
+            oldElement, newData, this.m_htmlFormElement);
+        //fetch the scripts and do an eval on the scripts to bypass
+        //browser inconsistencies in this area
+        //lets have the browser itself deal with this issue, j4fry
+        //is pretty well optimized in this area!
+        if (myfaces._impl._util._Utils.isManualScriptEval()) {
+            myfaces._impl._util._Utils.runScripts(request, context, newData);
+        }
+    };
+
+    /*insert, three attributes can be present
+     * id = insert id
+     * before = before id
+     * after = after  id
+     *
+     * the insert id is the id of the node to be inserted
+     * the before is the id if set which the component has to be inserted before
+     * 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) {
+        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) != "";
+
+        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");
+            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");
+            return false;
+        }
+        //either before or after but not two at the same time
+        if(beforeSet) {
+            beforeId = myfaces._impl._util._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");
+                return false;
+            }
+            /**
+             *we generate a temp holder
+             *so that we can use innerHTML for
+             *generating the content upfront
+             *before inserting it"
+             **/
+            var nodeHolder = document.createElement("div");
+            var parentNode = beforeNode.parentNode;
+            parentNode.insertBefore(nodeHolder, beforeNode);
+
+            myfaces._impl._util._Utils.replaceHtmlItem(request, context,
+                nodeHolder, node.firstChild.data, null);
+
+        } else {
+            afterId = myfaces._impl._util._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");
+                return false;
+            }
+            var nodeHolder = document.createElement("div");
+            var parentNode = afterNode.parentNode;
+            parentNode.insertBefore(nodeHolder, afterNode.nextSibling);
+            myfaces._impl._util._Utils.replaceHtmlItem(request, context,
+                nodeHolder, node.firstChild.data, null);
+        }
+        return true;
+    }
+
+    myfaces._impl.xhrCore._AjaxResponse.prototype.processDelete = function(request, context, node) {
+        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");
+            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
+        //IE quirks mode incompatibilities to the biggest possible extent
+        //most browsers just have to do a setAttributes but IE
+        //behaves as usual not like the official standard
+        //myfaces._impl._util._Utils.setAttribute(domNode, attribute, value;
+
+        //<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");
+            return false;
+        }
+        var childs = attributesRoot.childNodes;
+
+        if('undefined' == typeof childs || null == childs) {
+            return false;
+        }
+        for(var loop2 = 0; loop2 < childs.length; loop2++) {
+            var attributesNode = childs[loop2];
+
+            var attributeName = attributesNode.getAttribute("name");
+            var attributeValue = attributesNode.getAttribute("value");
+
+            if('undefined' == typeof attributeName || null == attributeName) {
+                continue;
+            }
+
+            attributeName = myfaces._impl._util._LangUtils.trim(attributeName);
+            /*no value means reset*/
+            if('undefined' == typeof attributeValue || null == attributeValue) {
+                attributeValue = "";
+            }
+
+            myfaces._impl._util._Utils.setAttribute(document.getElementById(elementId), attributeName, attributeValue);
+        }
+        return true;
+    }
+
 }
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js Sun May 31 09:32:13 2009
@@ -1,243 +1,243 @@
-/*
- * 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: werpu $)
- * Version: $Revision: 1.7 $ $Date: 2009/04/23 11:03:09 $
- *
- */
-
-_reserveMyfacesNamespaces();
-
-if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxUtils")) {
-
-    /**
-     * Constructor
-     * @param {String} alarmThreshold - Error Level
-     */
-    myfaces._impl.xhrCore._AjaxUtils = function(alarmThreshold) {
-        // Exception Objekt
-        this.alarmThreshold = alarmThreshold;
-        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxUtils", this.alarmThreshold);
-    };
-
-    /**
-     * determines fields to submit
-     * @param {HtmlElement} item - item that triggered the event
-     * @param {HtmlElement} parentItem - form element item is nested in
-     * @param {Array} partialIds - ids fo PPS
-     */
-    myfaces._impl.xhrCore._AjaxUtils.prototype.processUserEntries = function(request, context, item,
-        parentItem,	partialIds) {
-        try {
-            var form = parentItem;
-
-            if (form == null) {
-                this.m_exception.throwWarning(request, context, "processUserEntries",
-                    "Html-Component is not nested in a Form-Tag");
-                return null;
-            }
-
-            var stringBuffer = new Array();
-
-            if (partialIds != null && partialIds.length > 0) {
-                // recursivly check items
-                this.addNodes(form, false, partialIds, stringBuffer);
-            } else {
-                // add all nodes
-                var eLen = form.elements.length;
-                for ( var e = 0; e < eLen; e++) {
-                    this.addField(form.elements[e], stringBuffer);
-                } // end of for (formElements)
-            }
-
-            // if triggered by a Button send it along
-            if (item.type != null && item.type.toLowerCase() == "submit") {
-                stringBuffer[stringBuffer.length] = encodeURIComponent(item.name);
-                stringBuffer[stringBuffer.length] = "=";
-                stringBuffer[stringBuffer.length] = encodeURIComponent(item.value);
-                stringBuffer[stringBuffer.length] = "&";
-            }
-
-            return stringBuffer.join("");
-        } catch (e) {
-            alert(e);
-            this.m_exception.throwError(request, context, "processUserEntries", e);
-        }
-    };
-
-    /**
-     * checks recursively if contained in PPS
-     * @param {} node -
-     * @param {} insideSubmittedPart -
-     * @param {} partialIds -
-     * @param {} stringBuffer -
-     */
-    myfaces._impl.xhrCore._AjaxUtils.prototype.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._LangUtils.arrayContains(partialIds, id));
-                    if (insideSubmittedPart
-                        || isPartialSubmitContainer
-                        || (elementName != null
-                            && elementName == myfaces._impl.core._jsfImpl._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);
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * encapsulated xhr object which tracks down various implementations
-     * of the xhr object in a browser independend 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)
-     */
-    myfaces._impl.xhrCore._AjaxUtils.prototype.getXHRObject = function() {
-        if('undefined' != typeof XMLHttpRequest && null != XMLHttpRequest) {
-            return new XMLHttpRequest();
-        }
-        //IE
-        try {
-            return new ActiveXObject("Msxml2.XMLHTTP");
-        } catch (e) {
-            return new ActiveXObject('Microsoft.XMLHTTP');
-        }
-       
-    }
-
-
-    /**
-     * loads a script and executes it under a global scope
-     * @param {String} src the source to be loaded
-     * @param {String} type the mime type of the script (currently ignored
-     * but in the long run it will be used)
-     */
-    myfaces._impl.xhrCore._AjaxUtils.prototype.loadScript = function(src, type, defer, charSet) {
-        var xhr = this.getXHRObject();
-        xhr.open("GET", src, false);
-
-        if('undefined' != typeof charSet && null != charSet) {
-            xhr.setRequestHeader("Content-Type","application/x-javascript; charset:"+charSet);
-        }
-
-        xhr.send(null);
-
-        //since we are synchronous we do it after not with onReadyStateChange
-        if(xhr.readyState == 4) {
-            if (xhr.status == 200) {
-                //defer also means we have to process after the ajax response
-                //has been processed
-                //we can achieve that with a small timeout, the timeout
-                //triggers after the processing is done!
-                if(!defer) {
-                    myfaces._impl._util._Utils.globalEval(xhr.responseText);
-                } else {
-                   setTimeout(function() {
-                     myfaces._impl._util._Utils.globalEval(xhr.responseText);
-                   },1);
-                }
-            } else {
-                throw Error(xhr.responseText);
-            }
-        } else {
-            throw Error("Loading of script "+src+" failed ");
-        }
-    }
-
-
-
-    /**
-     * add a single field to stringbuffer for param submission
-     * @param {HtmlElement} element -
-     * @param {} stringBuffer -
-     */
-    myfaces._impl.xhrCore._AjaxUtils.prototype.addField = function(element, stringBuffer) {
-        var elementName = element.name;
-        var elementTagName = element.tagName.toLowerCase();
-        var elementType = element.type;
-        if (elementType != null) {
-            elementType = elementType.toLowerCase();
-        }
-
-        // routine for all elements
-        // rules:
-        // - process only inputs, textareas and selects
-        // - elements muest have attribute "name"
-        // - elements must not be disabled
-        if (((elementTagName == "input" || elementTagName == "textarea" || elementTagName == "select") &&
-            (elementName != null && elementName != "")) && element.disabled == false) {
-
-            // routine for select elements
-            // rules:
-            // - if select-one and value-Attribute exist => "name=value"
-            // (also if value empty => "name=")
-            // - if select-one and value-Attribute don't exist =>
-            // "name=DisplayValue"
-            // - if select multi and multple selected => "name=value1&name=value2"
-            // - if select and selectedIndex=-1 don't submit
-            if (elementTagName == "select") {
-                // selectedIndex must be >= 0 sein to be submittet
-                if (element.selectedIndex >= 0) {
-                    var uLen = element.options.length;
-                    for ( var u = 0; u < uLen; u++) {
-                        // find all selected options
-                        if (element.options[u].selected == true) {
-                            var elementOption = element.options[u];
-                            stringBuffer[stringBuffer.length] = encodeURIComponent(elementName);
-                            stringBuffer[stringBuffer.length] = "=";
-                            if (elementOption.getAttribute("value") != null) {
-                                stringBuffer[stringBuffer.length] = encodeURIComponent(elementOption.value);
-                            } else {
-                                stringBuffer[stringBuffer.length] = encodeURIComponent(elementOption.text);
-                            }
-                            stringBuffer[stringBuffer.length] = "&";
-                        }
-                    }
-                }
-            }
-
-            // routine for remaining elements
-            // rules:
-            // - don't submit no selects (processed above), buttons, reset buttons, submit buttons,
-            // - submit checkboxes and radio inputs only if checked
-            if ((elementTagName != "select" && elementType != "button"
-                && elementType != "reset" && elementType != "submit" && elementType != "image")
-            && ((elementType != "checkbox" && elementType != "radio") || element.checked)) {
-                stringBuffer[stringBuffer.length] = encodeURIComponent(elementName);
-                stringBuffer[stringBuffer.length] = "=";
-                stringBuffer[stringBuffer.length] = encodeURIComponent(element.value);
-                stringBuffer[stringBuffer.length] = "&";
-            }
-
-        }
-    }
+/*
+ * 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 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxUtils")) {
+
+    /**
+     * Constructor
+     * @param {String} alarmThreshold - Error Level
+     */
+    myfaces._impl.xhrCore._AjaxUtils = function(alarmThreshold) {
+        // Exception Objekt
+        this.alarmThreshold = alarmThreshold;
+        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxUtils", this.alarmThreshold);
+    };
+
+    /**
+     * determines fields to submit
+     * @param {HtmlElement} item - item that triggered the event
+     * @param {HtmlElement} parentItem - form element item is nested in
+     * @param {Array} partialIds - ids fo PPS
+     */
+    myfaces._impl.xhrCore._AjaxUtils.prototype.processUserEntries = function(request, context, item,
+        parentItem,	partialIds) {
+        try {
+            var form = parentItem;
+
+            if (form == null) {
+                this.m_exception.throwWarning(request, context, "processUserEntries",
+                    "Html-Component is not nested in a Form-Tag");
+                return null;
+            }
+
+            var stringBuffer = new Array();
+
+            if (partialIds != null && partialIds.length > 0) {
+                // recursivly check items
+                this.addNodes(form, false, partialIds, stringBuffer);
+            } else {
+                // add all nodes
+                var eLen = form.elements.length;
+                for ( var e = 0; e < eLen; e++) {
+                    this.addField(form.elements[e], stringBuffer);
+                } // end of for (formElements)
+            }
+
+            // if triggered by a Button send it along
+            if (item.type != null && item.type.toLowerCase() == "submit") {
+                stringBuffer[stringBuffer.length] = encodeURIComponent(item.name);
+                stringBuffer[stringBuffer.length] = "=";
+                stringBuffer[stringBuffer.length] = encodeURIComponent(item.value);
+                stringBuffer[stringBuffer.length] = "&";
+            }
+
+            return stringBuffer.join("");
+        } catch (e) {
+            alert(e);
+            this.m_exception.throwError(request, context, "processUserEntries", e);
+        }
+    };
+
+    /**
+     * checks recursively if contained in PPS
+     * @param {} node -
+     * @param {} insideSubmittedPart -
+     * @param {} partialIds -
+     * @param {} stringBuffer -
+     */
+    myfaces._impl.xhrCore._AjaxUtils.prototype.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._LangUtils.arrayContains(partialIds, id));
+                    if (insideSubmittedPart
+                        || isPartialSubmitContainer
+                        || (elementName != null
+                            && elementName == myfaces._impl.core._jsfImpl._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);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * encapsulated xhr object which tracks down various implementations
+     * of the xhr object in a browser independend 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)
+     */
+    myfaces._impl.xhrCore._AjaxUtils.prototype.getXHRObject = function() {
+        if('undefined' != typeof XMLHttpRequest && null != XMLHttpRequest) {
+            return new XMLHttpRequest();
+        }
+        //IE
+        try {
+            return new ActiveXObject("Msxml2.XMLHTTP");
+        } catch (e) {
+            return new ActiveXObject('Microsoft.XMLHTTP');
+        }
+       
+    }
+
+
+    /**
+     * loads a script and executes it under a global scope
+     * @param {String} src the source to be loaded
+     * @param {String} type the mime type of the script (currently ignored
+     * but in the long run it will be used)
+     */
+    myfaces._impl.xhrCore._AjaxUtils.prototype.loadScript = function(src, type, defer, charSet) {
+        var xhr = this.getXHRObject();
+        xhr.open("GET", src, false);
+
+        if('undefined' != typeof charSet && null != charSet) {
+            xhr.setRequestHeader("Content-Type","application/x-javascript; charset:"+charSet);
+        }
+
+        xhr.send(null);
+
+        //since we are synchronous we do it after not with onReadyStateChange
+        if(xhr.readyState == 4) {
+            if (xhr.status == 200) {
+                //defer also means we have to process after the ajax response
+                //has been processed
+                //we can achieve that with a small timeout, the timeout
+                //triggers after the processing is done!
+                if(!defer) {
+                    myfaces._impl._util._Utils.globalEval(xhr.responseText);
+                } else {
+                   setTimeout(function() {
+                     myfaces._impl._util._Utils.globalEval(xhr.responseText);
+                   },1);
+                }
+            } else {
+                throw Error(xhr.responseText);
+            }
+        } else {
+            throw Error("Loading of script "+src+" failed ");
+        }
+    }
+
+
+
+    /**
+     * add a single field to stringbuffer for param submission
+     * @param {HtmlElement} element -
+     * @param {} stringBuffer -
+     */
+    myfaces._impl.xhrCore._AjaxUtils.prototype.addField = function(element, stringBuffer) {
+        var elementName = element.name;
+        var elementTagName = element.tagName.toLowerCase();
+        var elementType = element.type;
+        if (elementType != null) {
+            elementType = elementType.toLowerCase();
+        }
+
+        // routine for all elements
+        // rules:
+        // - process only inputs, textareas and selects
+        // - elements muest have attribute "name"
+        // - elements must not be disabled
+        if (((elementTagName == "input" || elementTagName == "textarea" || elementTagName == "select") &&
+            (elementName != null && elementName != "")) && element.disabled == false) {
+
+            // routine for select elements
+            // rules:
+            // - if select-one and value-Attribute exist => "name=value"
+            // (also if value empty => "name=")
+            // - if select-one and value-Attribute don't exist =>
+            // "name=DisplayValue"
+            // - if select multi and multple selected => "name=value1&name=value2"
+            // - if select and selectedIndex=-1 don't submit
+            if (elementTagName == "select") {
+                // selectedIndex must be >= 0 sein to be submittet
+                if (element.selectedIndex >= 0) {
+                    var uLen = element.options.length;
+                    for ( var u = 0; u < uLen; u++) {
+                        // find all selected options
+                        if (element.options[u].selected == true) {
+                            var elementOption = element.options[u];
+                            stringBuffer[stringBuffer.length] = encodeURIComponent(elementName);
+                            stringBuffer[stringBuffer.length] = "=";
+                            if (elementOption.getAttribute("value") != null) {
+                                stringBuffer[stringBuffer.length] = encodeURIComponent(elementOption.value);
+                            } else {
+                                stringBuffer[stringBuffer.length] = encodeURIComponent(elementOption.text);
+                            }
+                            stringBuffer[stringBuffer.length] = "&";
+                        }
+                    }
+                }
+            }
+
+            // routine for remaining elements
+            // rules:
+            // - don't submit no selects (processed above), buttons, reset buttons, submit buttons,
+            // - submit checkboxes and radio inputs only if checked
+            if ((elementTagName != "select" && elementType != "button"
+                && elementType != "reset" && elementType != "submit" && elementType != "image")
+            && ((elementType != "checkbox" && elementType != "radio") || element.checked)) {
+                stringBuffer[stringBuffer.length] = encodeURIComponent(elementName);
+                stringBuffer[stringBuffer.length] = "=";
+                stringBuffer[stringBuffer.length] = encodeURIComponent(element.value);
+                stringBuffer[stringBuffer.length] = "&";
+            }
+
+        }
+    }
 }
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Exception.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Exception.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Exception.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Exception.js Sun May 31 09:32:13 2009
@@ -1,91 +1,91 @@
-/*
- * 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: werpu $)
- * Version: $Revision: 1.5 $ $Date: 2009/04/23 11:03:09 $
- *
- */
-
-_reserveMyfacesNamespaces();
-
-
-if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_Exception")) {
-
-
-    myfaces._impl.xhrCore._Exception = function(sourceClass, threshold) {
-        this.m_class = sourceClass
-        this.m_threshold = threshold
-    };
-
-    /**
- * [STATIC]
- * static method used by static methods that throw errors
- */
-    myfaces._impl.xhrCore._Exception.throwNewError = function(request, context, sourceClass, func, exception) {
-        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
- */
-    myfaces._impl.xhrCore._Exception.throwNewWarning = function(request, context, sourceClass, func, message){
-        newException = new myfaces._impl.xhrCore._Exception(request, context, sourceClass, "WARNING");
-        newException.throwWarning(request, context, func, message);
-    };
-
-    /**
- * throws errors
- */
-    myfaces._impl.xhrCore._Exception.prototype.throwError = function(request, context, func, exception) {
-        if (this.m_threshold == "ERROR") {
-            jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, exception.name,
-                "MyFaces ERROR\n"
-                + "Affected Class: " + this.m_class + "\n"
-                + "Affected Method: " + func + "\n"
-                + "Error name: " + exception.name + "\n"
-                + "Error message: " + exception.message + "\n"
-                + "Error description: " + exception.description	+ "\n"
-                + "Error number: " + exception.number + "\n"
-                + "Error line number: " + exception.lineNumber);
-        }
-        this.destroy();
-    };
-
-    /**
- * throws warnings
- */
-    myfaces._impl.xhrCore._Exception.prototype.throwWarning = function(request, context, func, message) {
-        if (this.m_threshold == "WARNING" || this.m_threshold == "ERROR") {
-            jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, exception.name,
-                "MyFaces WARNING\n[" + this.m_class + "::" + func + "]\n\n"
-                + message);
-        }
-        this.destroy();
-    };
-
-    /**
- * cleanup activities if an error occurs
- */
-    myfaces._impl.xhrCore._Exception.prototype.destroy = function() {
-        if (myfaces._impl.xhrCore._AjaxRequestQueue.queue &&
-            myfaces._impl.xhrCore._AjaxRequestQueue.queue != null) {
-            // clear RequestQueue when an exception occurs
-            myfaces._impl.xhrCore._AjaxRequestQueue.queue.clearQueue();
-        }
-    };
-
+/*
+ * 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.2 $ $Date: 2009/05/30 17:54:57 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+
+if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_Exception")) {
+
+
+    myfaces._impl.xhrCore._Exception = function(sourceClass, threshold) {
+        this.m_class = sourceClass
+        this.m_threshold = threshold
+    };
+
+    /**
+ * [STATIC]
+ * static method used by static methods that throw errors
+ */
+    myfaces._impl.xhrCore._Exception.throwNewError = function(request, context, sourceClass, func, exception) {
+        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
+ */
+    myfaces._impl.xhrCore._Exception.throwNewWarning = function(request, context, sourceClass, func, message){
+        newException = new myfaces._impl.xhrCore._Exception(request, context, sourceClass, "WARNING");
+        newException.throwWarning(request, context, func, message);
+    };
+
+    /**
+ * throws errors
+ */
+    myfaces._impl.xhrCore._Exception.prototype.throwError = function(request, context, func, exception) {
+        if (this.m_threshold == "ERROR") {
+        	myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, exception.name,
+                "MyFaces ERROR\n"
+                + "Affected Class: " + this.m_class + "\n"
+                + "Affected Method: " + func + "\n"
+                + "Error name: " + exception.name + "\n"
+                + "Error message: " + exception.message + "\n"
+                + "Error description: " + exception.description	+ "\n"
+                + "Error number: " + exception.number + "\n"
+                + "Error line number: " + exception.lineNumber);
+        }
+        this.destroy();
+    };
+
+    /**
+ * throws warnings
+ */
+    myfaces._impl.xhrCore._Exception.prototype.throwWarning = function(request, context, func, message) {
+        if (this.m_threshold == "WARNING" || this.m_threshold == "ERROR") {
+        	myfaces.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, exception.name,
+                "MyFaces WARNING\n[" + this.m_class + "::" + func + "]\n\n"
+                + message);
+        }
+        this.destroy();
+    };
+
+    /**
+ * cleanup activities if an error occurs
+ */
+    myfaces._impl.xhrCore._Exception.prototype.destroy = function() {
+        if (myfaces._impl.xhrCore._AjaxRequestQueue.queue &&
+            myfaces._impl.xhrCore._AjaxRequestQueue.queue != null) {
+            // clear RequestQueue when an exception occurs
+            myfaces._impl.xhrCore._AjaxRequestQueue.queue.clearQueue();
+        }
+    };
+
 }
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js Sun May 31 09:32:13 2009
@@ -1,65 +1,65 @@
-/*
- * 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: werpu $)
- * Version: $Revision: 1.9 $ $Date: 2009/04/23 11:03:09 $
- *
- */
-
-_reserveMyfacesNamespaces();
-
-if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_Ajax")) {
-
-
-    /**
-     * Constructor
-     */
-    myfaces._impl.xhrCore._Ajax = function() {}
-
-    /**
-     * Spec. 13.3.1
-     * Collect and encode input elements.
-     * Additinoaly the hidden element javax.faces.ViewState
-     * @param {String} FORM_ELEMENT - Client-Id of Form-Element
-     * @return {String} - Concatenated String of the encoded input elements
-     * 			and javax.faces.ViewState element
-     */
-    myfaces._impl.xhrCore._Ajax.prototype.getViewState = function(FORM_ELEMENT) {
-        return myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.getViewState();
-    }
-
-
-    /**
-     * mapped options already have the exec and view properly in place
-     * myfaces specifics can be found under mappedOptions.myFaces
-     * @param ajaxContext the ajax context which also has to be pushed into the messages and into the response
-     **/
-
-    myfaces._impl.xhrCore._Ajax.prototype._ajaxRequest = function(source, sourceForm, context, passThroughValues ) {
-        myfaces._impl.xhrCore._AjaxRequestQueue.queue.queueRequest(
-            new myfaces._impl.xhrCore._AjaxRequest(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
-     */
-    myfaces._impl.xhrCore._Ajax.prototype._ajaxResponse = function(request, context) {
-        myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.m_response.processResponse(request, context);
-    }
-
+/*
+ * 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 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_Ajax")) {
+
+
+    /**
+     * Constructor
+     */
+    myfaces._impl.xhrCore._Ajax = function() {}
+
+    /**
+     * Spec. 13.3.1
+     * Collect and encode input elements.
+     * Additinoaly the hidden element javax.faces.ViewState
+     * @param {String} FORM_ELEMENT - Client-Id of Form-Element
+     * @return {String} - Concatenated String of the encoded input elements
+     * 			and javax.faces.ViewState element
+     */
+    myfaces._impl.xhrCore._Ajax.prototype.getViewState = function(FORM_ELEMENT) {
+        return myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.getViewState();
+    }
+
+
+    /**
+     * mapped options already have the exec and view properly in place
+     * myfaces specifics can be found under mappedOptions.myFaces
+     * @param ajaxContext the ajax context which also has to be pushed into the messages and into the response
+     **/
+
+    myfaces._impl.xhrCore._Ajax.prototype._ajaxRequest = function(source, sourceForm, context, passThroughValues ) {
+        myfaces._impl.xhrCore._AjaxRequestQueue.queue.queueRequest(
+            new myfaces._impl.xhrCore._AjaxRequest(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
+     */
+    myfaces._impl.xhrCore._Ajax.prototype._ajaxResponse = function(request, context) {
+        myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.m_response.processResponse(request, context);
+    }
+
 }
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js Sun May 31 09:32:13 2009
@@ -33,21 +33,16 @@
     jsf = new Object();
 }
 
-/*
- *just to make sure no questions arise, I simply prefer here a weak
- *typeless comparison just in case some frameworks try to interfere
- *by overriding null or fiddeling around with undefined or typeof in some ways
- *it is safer in this case than the standard way of doing a strong comparison
+/**
+ * just to make sure no questions arise, I simply prefer here a weak
+ * typeless comparison just in case some frameworks try to interfere
+ * by overriding null or fiddeling around with undefined or typeof in some ways
+ * it is safer in this case than the standard way of doing a strong comparison
  **/
 if ('undefined' == typeof jsf.ajax || null == jsf.ajax) {
     jsf.ajax = new Object();
 
-    //todo make this overridable by a configuration option
-    /*
-     myfaces.
-     */
-
-     jsf.ajax._impl = new (myfaces._impl._util._Utils.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core._jsfImpl))();
+     jsf.ajax._impl = myfaces._impl._util._Utils.getGlobalConfig("jsfAjaxImpl", myfaces.ajax);
 
     /**
      * collect and encode data for a given form element (must be of type form)
@@ -73,7 +68,7 @@
      * </ul>
      *
      * @param {String|Node} element: any dom element no matter being it html or jsf, from which the event is emitted
-     * @param {|EVENT|}Êevent: any javascript event supported by that object
+     * @param {|EVENT|} event: any javascript event supported by that object
      * @param {Map||} options : map of options being pushed into the ajax cycle
      */
     jsf.ajax.request = function( element,  event,  options) {



Mime
View raw message