myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gan...@apache.org
Subject svn commit: r780394 [1/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
Author: ganesh
Date: Sun May 31 09:32:13 2009
New Revision: 780394

URL: http://svn.apache.org/viewvc?rev=780394&view=rev
Log:
JIRA MYFACES-2238

Removed:
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Extensions.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_VbsUtils.vbs
Modified:
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Exception.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_xhrCoreAdapter.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/api/jsf.js

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js Sun May 31 09:32:13 2009
@@ -1,473 +1,470 @@
-/*
- * 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/05/06 11:06:36 $
- *
- */
-
-_reserveMyfacesNamespaces();
-
-if(!myfaces._impl._util._LangUtils.exists(myfaces._impl._util,"_Utils")) {
-    /**
-     * Constructor
-     */
-    myfaces._impl._util._Utils = function() {
-
-    }
-
-
-    myfaces._impl._util._Utils.browserDetection = function() {
-        /**
-         * browser detection code
-         * cross ported from dojo 1.2
-         *
-         * dojos browser detection code is very sophisticated
-         * 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!
-         *
-         * the exception is the ie detection which relies on specific quirks in ie
-         */
-       	var n = navigator;
-        var dua = n.userAgent,
-        dav = n.appVersion,
-        tv = parseFloat(dav);
-
-        myfaces._impl._util._Utils.browser = {};
-        var d = myfaces._impl._util._Utils.browser;
-
-        if(dua.indexOf("Opera") >= 0){
-            myfaces._impl._util._Utils.isOpera = tv;
-        }
-        if(dua.indexOf("AdobeAIR") >= 0){
-            d.isAIR = 1;
-        }
-        d.isKhtml = (dav.indexOf("Konqueror") >= 0) ? tv : 0;
-        d.isWebKit = parseFloat(dua.split("WebKit/")[1]) || undefined;
-        d.isChrome = parseFloat(dua.split("Chrome/")[1]) || undefined;
-
-        // safari detection derived from:
-        //		http://developer.apple.com/internet/safari/faq.html#anchor2
-        //		http://developer.apple.com/internet/safari/uamatrix.html
-        var index = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0);
-        if(index && !d.isChrome){
-            // try to grab the explicit Safari version first. If we don't get
-            // one, look for less than 419.3 as the indication that we're on something
-            // "Safari 2-ish".
-            d.isSafari = parseFloat(dav.split("Version/")[1]);
-            if(!d.isSafari || parseFloat(dav.substr(index + 7)) <= 419.3){
-                d.isSafari = 2;
-            }
-        }
-
-        //>>excludeStart("webkitMobile", kwArgs.webkitMobile);
-        if(dua.indexOf("Gecko") >= 0 && !d.isKhtml && !d.isWebKit){
-            d.isMozilla = d.isMoz = tv;
-        }
-        if(d.isMoz){
-            //We really need to get away from this. Consider a sane isGecko approach for the future.
-            d.isFF = parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1] || dua.split("Shiretoko/")[1]) || undefined;
-        }
-        if(document.all && !d.isOpera){
-            d.isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;
-            //In cases where the page has an HTTP header or META tag with
-            //X-UA-Compatible, then it is in emulation mode, for a previous
-            //version. Make sure isIE reflects the desired version.
-            //document.documentMode of 5 means quirks mode.
-            if(d.isIE >= 8 && document.documentMode != 5){
-                d.isIE = document.documentMode;
-            }
-        }
-    };
-
-  
-
-    /**
-     * [STATIC]
-     * Run through the given Html item and execute the inline scripts
-     * (IE doesn't do this by itself)
-     * @param {XMLHTTPRequest} request
-     * @param {Map} context
-     * @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') {
-                try {
-                    var test = item.text;
-                    var go = true;
-                    while (go) {
-                        go = false;
-                        if (test.substring(0, 1) == " ") {
-                            test = test.substring(1);
-                            go = true;
-                        }
-                        if (test.substring(0, 4) == "<!--") {
-                            test = test.substring(4);
-                            go = true;
-                        }
-                        if (test.substring(0, 11) == "//<![CDATA[") {
-                            test = test.substring(11);
-                            go = true;
-                        }
-                    }
-                    /*we have to run the script under a global context*/
-                    myfaces._impl._util._Utils.globalEval(test); // run the script
-                } catch (e) {
-                    myfaces._impl.xhrCore._Exception.throwNewError(request, context, "Utils", "runScripts", e);
-                }
-            } else {
-                var child = item.firstChild;
-                while (child) {
-                    myfaces._impl._util._Utils.runScripts(request, context, child);
-                    child = child.nextSibling;
-                }
-            }
-        }
-    }
-
-    /**
-     * Simple delete on an existing item
-     */
-    myfaces._impl._util._Utils.deleteItem = function(request, context, itemIdToReplace) {
-        var item = document.getElementById(itemIdToReplace);
-        if (item == null) {
-            myfaces._impl.xhrCore._Exception.throwNewWarning
-            (request, context, "Utils", "deleteItem", "Unknown Html-Component-ID: " + itemIdToReplace);
-            return;
-        }
-
-        item.parentNode.removeChild(item);
-    }
-
-    /**
-     * [STATIC]
-     * Replaces HTML elements through others
-     * @param {XMLHTTPRequest} request
-     * @param {Map} context
-     * @param {String|node} itemIdToReplace - ID of the element to replace
-     * @param {String} newTag - the new tag
-     * @param {HTML Element} form - form element that is parent of the element
-     */
-    myfaces._impl._util._Utils.replaceHtmlItem = function(request, context, itemIdToReplace, newTag, form) {
-        try {
-
-
-            var item = (itemIdToReplace instanceof Node) ? itemIdToReplace :
-                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;
-            }
-
-            if (newTag != "") {
-                if (typeof window.Range != 'undefined'
-                    && typeof Range.prototype.createContextualFragment == 'function') {
-                    var range = document.createRange();
-                    range.setStartBefore(item);
-                    var fragment = range.createContextualFragment(newTag);
-                    item.parentNode.insertBefore(fragment, item);
-                } else {
-                    item.insertAdjacentHTML('beforeBegin', newTag);
-                }
-                if (myfaces._impl._util._Utils.isManualScriptEval()) {
-                    myfaces._impl._util._Utils.runScripts(request, context, item.previousSibling);
-                }
-            }
-
-            // and remove the old item
-            item.parentNode.removeChild(item);
-        } catch (e) {
-            myfaces._impl.xhrCore._Exception.throwNewError (request, context, "Utils", "replaceHTMLItem", e);
-        }
-    };
-
-
-    myfaces._impl._util._Utils.ieQuircksEvents = {
-        "onabort": true,
-        "onload":true,
-        "onunload":true,
-        "onchange": true,
-        "onsubmit": true,
-        "onreset": true,
-        "onselect": true,
-        "onblur": true,
-        "onfocus": true,
-        "onkeydown": true,
-        "onkeypress": true,
-        "onkeyup": true,
-        "onclick": true,
-        "ondblclick": true,
-        "onmousedown": true,
-        "onmousemove": true,
-        "onmouseout": true,
-        "onmouseover": true,
-        "onmouseup": true
-    };
-
-    /**
-     * bugfixing for ie6 which does not cope properly with setAttribute
-     */
-    myfaces._impl._util._Utils.setAttribute = function(domNode, attribute, value) {
-
-        if(!myfaces._impl._util._Utils.isUserAgentInternetExplorer()) {
-            domNode.setAttribute(attribute,value);
-            return;
-        }
-        //Now to the broken browsers IE6+.... ie7 and ie8 quirks mode
-
-
-        //now ie has the behavior of not wanting events to be set directly and also
-        //class must be renamed to classname
-        //according to http://www.quirksmode.org/dom/w3c_core.html it does not set styles
-        //also class == className we have to rechange that
-        //additionally events are not triggered as well
-
-        //what we do is following for now:
-        //1. remap the class
-        attribute = attribute.toLowerCase();
-
-        if(attribute === "class") {
-            domNode["className"] = value;
-        } else if(attribute === style) {
-            //We have to split the styles here and assign them one by one
-            var styleEntries = value.split(";");
-            for(var loop = 0; loop < styleEntries.length; loop++) {
-                var keyVal = styleEntries[loop].split(":");
-                domNode["style"][keyVal[0]] = keyVal[1];
-            }
-        } else {
-            //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._LangUtils.isString(attribute)) {
-                    domNode[attribute] = function(event) {
-                        //TODO check the scope of this handler
-                        myfaces._impl._util._Utils.globalEval(attribute);
-                    };
-                }
-            }
-            domNode[attribute] = value;
-        }
-        //TODO this needs further testing I will leave it for now...
-    };
-
-    /**
-     * determines if the embedded scripts have to be evaled manually
-     * @return true if a browser combination is given which has to
-     * do a manual eval
-     * which is currently ie > 5.5, chrome, khtml, webkit safari
-     *
-     */
-    myfaces._impl._util._Utils.isManualScriptEval = function() {
-        var _LangUtils = myfaces._impl._util._LangUtils;
-        //TODO test this with various browsers so that we have auto eval wherever possible
-        //
-        //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") &&
-            _LangUtils.exists(myfaces._impl._util._Utils.browser.isKhtml > 0))   ||
-            (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isWebKit") &&
-            _LangUtils.exists(myfaces._impl._util._Utils.browser.isWebKit > 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
-        //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
-       
-    };
-
-    /**
-     * [STATIC]
-     * Determines whether the user agent is IE or not
-     * @return {boolean} - true if it is IE
-     */
-    myfaces._impl._util._Utils.isUserAgentInternetExplorer = function() {
-        return myfaces._impl._util._Utils.browser.isIE;
-    };
-
-    /**
-     * [STATIC]
-     * gets an element from a form with its id -> sometimes two elements have got
-     * the same id but are located in different forms -> MyFaces 1.1.4 two forms ->
-     * 2 inputHidden fields with ID jsf_tree_64 & jsf_state_64 ->
-     * http://www.arcknowledge.com/gmane.comp.jakarta.myfaces.devel/2005-09/msg01269.html
-     * @param {XMLHTTPRequest} request
-     * @param {Map} context
-     * @param {String} itemIdOrName - ID of the HTML element located inside the form
-     * @param {Html-Element} form - form element containing the element
-     * @param {boolean} nameSearch if set to true a search for name is also done
-     * @param {boolean} localSearchOnly if set to true a local search is performed only (a full document search is omitted)
-     * @return {Html-Element} - return the element if found else null
-     *
-     */
-    myfaces._impl._util._Utils.getElementFromForm = function(request, context, itemIdOrName, form, nameSearch, localSearchOnly) {
-        try {
-
-            if('undefined' == typeof form || form == null) {
-                return document.getElementById(itemIdOrName);
-            }
-            if('undefined' == typeof includeName || nameSearch == null) {
-                nameSearch = false;
-            }
-            if('undefined' == typeof localSearchOnly || localSearchOnly == null) {
-                localSearchOnly = false;
-            }
-
-
-            var fLen = form.elements.length;
-            
-            //we first check for a name entry!
-            if(nameSearch && 'undefined' != typeof form.elements[itemIdOrName] && null != form.elements[itemIdOrName]) {
-                return element;
-            }
-            //if no name entry is found we check for an Id
-            for ( var f = 0; f < fLen; f++) {
-                var element = form.elements[f];
-                if (element.id != null && element.id == itemIdOrName) {
-                    return element;
-                }
-                
-            }
-            // element not found inside the form -> try document.getElementById
-            // (kann be null if element doesn't exist)
-            if(!localSearchOnly) {
-                return document.getElementById(itemIdOrName);
-            }
-        } catch (e) {
-            myfaces._impl.xhrCore._Exception.throwNewError(request, context, "Utils", "getElementFromForm", e);
-        }
-        return null;
-    };
-
-
-
-    /**
-     * [STATIC]
-     * gets a parent of an item with a given tagname
-     * @param {XMLHTTPRequest} request
-     * @param {Map} context
-     * @param {HtmlElement} item - child element
-     * @param {String} parentName - TagName of parent element
-     */
-    myfaces._impl._util._Utils.getParent = function(request, context, item, parentName) {
-        try {
-            // parent tag parentName suchen
-            var parentItem = item.parentNode;
-            while (parentItem != null
-                && parentItem.tagName.toLowerCase() != parentName) {
-                parentItem = parentItem.parentNode;
-            }
-            if (parentItem != null) {
-                return parentItem;
-            } else {
-                myfaces._impl.xhrCore._Exception.throwNewWarning
-                (request, context, "Utils", "getParent", "The item has no parent with type <" + parentName + ">");
-                return null;
-            }
-        } catch (e) {
-            myfaces._impl.xhrCore._Exception.throwNewError (request, context, "Utils", "getParent", e);
-        }
-    };
-
-    /**
-     * [STATIC]
-     * gets the child of an item with a given tagname
-     * @param {HtmlElement} item - parent element
-     * @param {String} childName - TagName of child element
-     * @param {String} itemName - name-Attribut the child can have (can be null)
-     */
-    myfaces._impl._util._Utils.getChild = function(item, childName, itemName) {
-        var childItems = item.childNodes;
-        for ( var c = 0, cLen = childItems.length; c < cLen; c++) {
-            if (childItems[c].tagName != null
-                && childItems[c].tagName.toLowerCase() == childName
-                && (itemName == null || (itemName != null && itemName == childItems[c]
-            .getAttribute("name")))) {
-                return childItems[c];
-            }
-        }
-        return null;
-    }
-
-
-  
-
-
-    /**
-     * fetches a global config entry
-     * @param {String} configName the name of the configuration entry
-     * @param {Object} defaultValur
-     *
-     * @return either the config entry or if none is given the default value
-     */
-    myfaces._impl._util._Utils.getGlobalConfig = function(configName, defaultValue) {
-        /*use(myfaces._impl._util)*/
-        var _LangUtils = myfaces._impl._util._LangUtils;
-
-        if (_LangUtils.exists(myfaces,"config") && _LangUtils.exists(myfaces.config,configName)) {
-            return myfaces.config[configName];
-        }
-        return defaultValue;
-    };
-
-    /**
-     * global eval on scripts
-     * 
-     */
-    myfaces._impl._util._Utils.globalEval = function(code) {
-
-        if (window.execScript) {
-            window.execScript(code);
-            return;
-        }
-
-        eval.call(null, code);
-    }
-
-    /**
-     * gets the local or global options with local ones having higher priority
-     * if no local or global one was found then the default value is given back
-     *
-     * @param {String} configName the name of the configuration entry
-     * @param {String} localOptions the local options root for the configuration myfaces as default marker is added implicitely
-     *
-     * @param {Object} defaultValue
-     *
-     * @return either the config entry or if none is given the default value
-     */
-    myfaces._impl._util._Utils.getLocalOrGlobalConfig = function(configName, localOptions, defaultValue) {
-        /*use(myfaces._impl._util)*/
-        var _LangUtils = myfaces._impl._util._LangUtils;
-
-        var globalOption = myfaces._impl._util._Utils.getGlobalConfig(configName, defaultValue);
-        if(!_LangUtils.exists(localOptions, "myfaces") || !_LangUtils.exists(localOptions.myfaces,configName)) {
-            return globalOption;
-        }
-        return localOptions.myfaces[configName];
-    };
-
-    myfaces._impl._util._Utils.browserDetection();
-}
+/*
+ * 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/31 09:16:43 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+if(!myfaces._impl._util._LangUtils.exists(myfaces._impl._util,"_Utils")) {
+    /**
+     * Constructor
+     */
+    myfaces._impl._util._Utils = function() {
+
+    }
+
+
+    myfaces._impl._util._Utils.browserDetection = function() {
+        /**
+         * browser detection code
+         * cross ported from dojo 1.2
+         *
+         * dojos browser detection code is very sophisticated
+         * 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!
+         *
+         * the exception is the ie detection which relies on specific quirks in ie
+         */
+       	var n = navigator;
+        var dua = n.userAgent,
+        dav = n.appVersion,
+        tv = parseFloat(dav);
+
+        myfaces._impl._util._Utils.browser = {};
+        var d = myfaces._impl._util._Utils.browser;
+
+        if(dua.indexOf("Opera") >= 0){
+            myfaces._impl._util._Utils.isOpera = tv;
+        }
+        if(dua.indexOf("AdobeAIR") >= 0){
+            d.isAIR = 1;
+        }
+        d.isKhtml = (dav.indexOf("Konqueror") >= 0) ? tv : 0;
+        d.isWebKit = parseFloat(dua.split("WebKit/")[1]) || undefined;
+        d.isChrome = parseFloat(dua.split("Chrome/")[1]) || undefined;
+
+        // safari detection derived from:
+        //		http://developer.apple.com/internet/safari/faq.html#anchor2
+        //		http://developer.apple.com/internet/safari/uamatrix.html
+        var index = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0);
+        if(index && !d.isChrome){
+            // try to grab the explicit Safari version first. If we don't get
+            // one, look for less than 419.3 as the indication that we're on something
+            // "Safari 2-ish".
+            d.isSafari = parseFloat(dav.split("Version/")[1]);
+            if(!d.isSafari || parseFloat(dav.substr(index + 7)) <= 419.3){
+                d.isSafari = 2;
+            }
+        }
+
+        //>>excludeStart("webkitMobile", kwArgs.webkitMobile);
+        if(dua.indexOf("Gecko") >= 0 && !d.isKhtml && !d.isWebKit){
+            d.isMozilla = d.isMoz = tv;
+        }
+        if(d.isMoz){
+            //We really need to get away from this. Consider a sane isGecko approach for the future.
+            d.isFF = parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1] || dua.split("Shiretoko/")[1]) || undefined;
+        }
+        if(document.all && !d.isOpera){
+            d.isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;
+            //In cases where the page has an HTTP header or META tag with
+            //X-UA-Compatible, then it is in emulation mode, for a previous
+            //version. Make sure isIE reflects the desired version.
+            //document.documentMode of 5 means quirks mode.
+            if(d.isIE >= 8 && document.documentMode != 5){
+                d.isIE = document.documentMode;
+            }
+        }
+    };
+
+  
+
+    /**
+     * [STATIC]
+     * Run through the given Html item and execute the inline scripts
+     * (IE doesn't do this by itself)
+     * @param {XMLHTTPRequest} request
+     * @param {Map} context
+     * @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') {
+                try {
+                    var test = item.text;
+                    var go = true;
+                    while (go) {
+                        go = false;
+                        if (test.substring(0, 1) == " ") {
+                            test = test.substring(1);
+                            go = true;
+                        }
+                        if (test.substring(0, 4) == "<!--") {
+                            test = test.substring(4);
+                            go = true;
+                        }
+                        if (test.substring(0, 11) == "//<![CDATA[") {
+                            test = test.substring(11);
+                            go = true;
+                        }
+                    }
+                    /*we have to run the script under a global context*/
+                    myfaces._impl._util._Utils.globalEval(test); // run the script
+                } catch (e) {
+                    myfaces._impl.xhrCore._Exception.throwNewError(request, context, "Utils", "runScripts", e);
+                }
+            } else {
+                var child = item.firstChild;
+                while (child) {
+                    myfaces._impl._util._Utils.runScripts(request, context, child);
+                    child = child.nextSibling;
+                }
+            }
+        }
+    }
+
+    /**
+     * Simple delete on an existing item
+     */
+    myfaces._impl._util._Utils.deleteItem = function(request, context, itemIdToReplace) {
+        var item = document.getElementById(itemIdToReplace);
+        if (item == null) {
+            myfaces._impl.xhrCore._Exception.throwNewWarning
+            (request, context, "Utils", "deleteItem", "Unknown Html-Component-ID: " + itemIdToReplace);
+            return;
+        }
+
+        item.parentNode.removeChild(item);
+    }
+
+    /**
+     * [STATIC]
+     * Replaces HTML elements through others
+     * @param {XMLHTTPRequest} request
+     * @param {Map} context
+     * @param {String|node} itemIdToReplace - ID of the element to replace
+     * @param {String} newTag - the new tag
+     * @param {HTML Element} form - form element that is parent of the element
+     */
+    myfaces._impl._util._Utils.replaceHtmlItem = function(request, context, itemIdToReplace, newTag, form) {
+        try {
+
+            var item = (itemIdToReplace instanceof Node) ? itemIdToReplace :
+                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;
+            }
+
+            if (newTag != "") {
+                if (typeof window.Range != 'undefined'
+                    && typeof Range.prototype.createContextualFragment == 'function') {
+                    var range = document.createRange();
+                    range.setStartBefore(item);
+                    var fragment = range.createContextualFragment(newTag);
+                    item.parentNode.insertBefore(fragment, item);
+                } else {
+                    item.insertAdjacentHTML('beforeBegin', newTag);
+                    myfaces._impl._util._Utils.runScripts(request, context, item.previousSibling);
+                }
+            }
+
+            // and remove the old item
+            item.parentNode.removeChild(item);
+        } catch (e) {
+            myfaces._impl.xhrCore._Exception.throwNewError (request, context, "Utils", "replaceHTMLItem", e);
+        }
+    };
+
+
+    myfaces._impl._util._Utils.ieQuircksEvents = {
+        "onabort": true,
+        "onload":true,
+        "onunload":true,
+        "onchange": true,
+        "onsubmit": true,
+        "onreset": true,
+        "onselect": true,
+        "onblur": true,
+        "onfocus": true,
+        "onkeydown": true,
+        "onkeypress": true,
+        "onkeyup": true,
+        "onclick": true,
+        "ondblclick": true,
+        "onmousedown": true,
+        "onmousemove": true,
+        "onmouseout": true,
+        "onmouseover": true,
+        "onmouseup": true
+    };
+
+    /**
+     * bugfixing for ie6 which does not cope properly with setAttribute
+     */
+    myfaces._impl._util._Utils.setAttribute = function(domNode, attribute, value) {
+
+        if(!myfaces._impl._util._Utils.isUserAgentInternetExplorer()) {
+            domNode.setAttribute(attribute,value);
+            return;
+        }
+        //Now to the broken browsers IE6+.... ie7 and ie8 quirks mode
+
+
+        //now ie has the behavior of not wanting events to be set directly and also
+        //class must be renamed to classname
+        //according to http://www.quirksmode.org/dom/w3c_core.html it does not set styles
+        //also class == className we have to rechange that
+        //additionally events are not triggered as well
+
+        //what we do is following for now:
+        //1. remap the class
+        attribute = attribute.toLowerCase();
+
+        if(attribute === "class") {
+            domNode["className"] = value;
+        } else if(attribute === style) {
+            //We have to split the styles here and assign them one by one
+            var styleEntries = value.split(";");
+            for(var loop = 0; loop < styleEntries.length; loop++) {
+                var keyVal = styleEntries[loop].split(":");
+                domNode["style"][keyVal[0]] = keyVal[1];
+            }
+        } else {
+            //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._LangUtils.isString(attribute)) {
+                    domNode[attribute] = function(event) {
+                        //TODO check the scope of this handler
+                        myfaces._impl._util._Utils.globalEval(attribute);
+                    };
+                }
+            }
+            domNode[attribute] = value;
+        }
+        //TODO this needs further testing I will leave it for now...
+    };
+
+    /**
+     * determines if the embedded scripts have to be evaled manually
+     * @return true if a browser combination is given which has to
+     * do a manual eval
+     * which is currently ie > 5.5, chrome, khtml, webkit safari
+     *
+     */
+    myfaces._impl._util._Utils.isManualScriptEval = function() {
+        var _LangUtils = myfaces._impl._util._LangUtils;
+        //TODO test this with various browsers so that we have auto eval wherever possible
+        //
+        //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") &&
+            _LangUtils.exists(myfaces._impl._util._Utils.browser.isKhtml > 0))   ||
+            (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isWebKit") &&
+            _LangUtils.exists(myfaces._impl._util._Utils.browser.isWebKit > 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
+        //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
+       
+    };
+
+    /**
+     * [STATIC]
+     * Determines whether the user agent is IE or not
+     * @return {boolean} - true if it is IE
+     */
+    myfaces._impl._util._Utils.isUserAgentInternetExplorer = function() {
+        return myfaces._impl._util._Utils.browser.isIE;
+    };
+
+    /**
+     * [STATIC]
+     * gets an element from a form with its id -> sometimes two elements have got
+     * the same id but are located in different forms -> MyFaces 1.1.4 two forms ->
+     * 2 inputHidden fields with ID jsf_tree_64 & jsf_state_64 ->
+     * http://www.arcknowledge.com/gmane.comp.jakarta.myfaces.devel/2005-09/msg01269.html
+     * @param {XMLHTTPRequest} request
+     * @param {Map} context
+     * @param {String} itemIdOrName - ID of the HTML element located inside the form
+     * @param {Html-Element} form - form element containing the element
+     * @param {boolean} nameSearch if set to true a search for name is also done
+     * @param {boolean} localSearchOnly if set to true a local search is performed only (a full document search is omitted)
+     * @return {Html-Element} - return the element if found else null
+     *
+     */
+    myfaces._impl._util._Utils.getElementFromForm = function(request, context, itemIdOrName, form, nameSearch, localSearchOnly) {
+        try {
+
+            if('undefined' == typeof form || form == null) {
+                return document.getElementById(itemIdOrName);
+            }
+            if('undefined' == typeof includeName || nameSearch == null) {
+                nameSearch = false;
+            }
+            if('undefined' == typeof localSearchOnly || localSearchOnly == null) {
+                localSearchOnly = false;
+            }
+
+
+            var fLen = form.elements.length;
+            
+            //we first check for a name entry!
+            if(nameSearch && 'undefined' != typeof form.elements[itemIdOrName] && null != form.elements[itemIdOrName]) {
+                return element;
+            }
+            //if no name entry is found we check for an Id
+            for ( var f = 0; f < fLen; f++) {
+                var element = form.elements[f];
+                if (element.id != null && element.id == itemIdOrName) {
+                    return element;
+                }
+                
+            }
+            // element not found inside the form -> try document.getElementById
+            // (kann be null if element doesn't exist)
+            if(!localSearchOnly) {
+                return document.getElementById(itemIdOrName);
+            }
+        } catch (e) {
+            myfaces._impl.xhrCore._Exception.throwNewError(request, context, "Utils", "getElementFromForm", e);
+        }
+        return null;
+    };
+
+
+
+    /**
+     * [STATIC]
+     * gets a parent of an item with a given tagname
+     * @param {XMLHTTPRequest} request
+     * @param {Map} context
+     * @param {HtmlElement} item - child element
+     * @param {String} parentName - TagName of parent element
+     */
+    myfaces._impl._util._Utils.getParent = function(request, context, item, parentName) {
+        try {
+            // parent tag parentName suchen
+            var parentItem = item.parentNode;
+            while (parentItem != null
+                && parentItem.tagName.toLowerCase() != parentName) {
+                parentItem = parentItem.parentNode;
+            }
+            if (parentItem != null) {
+                return parentItem;
+            } else {
+                myfaces._impl.xhrCore._Exception.throwNewWarning
+                (request, context, "Utils", "getParent", "The item has no parent with type <" + parentName + ">");
+                return null;
+            }
+        } catch (e) {
+            myfaces._impl.xhrCore._Exception.throwNewError (request, context, "Utils", "getParent", e);
+        }
+    };
+
+    /**
+     * [STATIC]
+     * gets the child of an item with a given tagname
+     * @param {HtmlElement} item - parent element
+     * @param {String} childName - TagName of child element
+     * @param {String} itemName - name-Attribut the child can have (can be null)
+     */
+    myfaces._impl._util._Utils.getChild = function(item, childName, itemName) {
+        var childItems = item.childNodes;
+        for ( var c = 0, cLen = childItems.length; c < cLen; c++) {
+            if (childItems[c].tagName != null
+                && childItems[c].tagName.toLowerCase() == childName
+                && (itemName == null || (itemName != null && itemName == childItems[c]
+            .getAttribute("name")))) {
+                return childItems[c];
+            }
+        }
+        return null;
+    }
+
+
+  
+
+
+    /**
+     * fetches a global config entry
+     * @param {String} configName the name of the configuration entry
+     * @param {Object} defaultValur
+     *
+     * @return either the config entry or if none is given the default value
+     */
+    myfaces._impl._util._Utils.getGlobalConfig = function(configName, defaultValue) {
+        /*use(myfaces._impl._util)*/
+        var _LangUtils = myfaces._impl._util._LangUtils;
+
+        if (_LangUtils.exists(myfaces,"config") && _LangUtils.exists(myfaces.config,configName)) {
+            return myfaces.config[configName];
+        }
+        return defaultValue;
+    };
+
+    /**
+     * global eval on scripts
+     * 
+     */
+    myfaces._impl._util._Utils.globalEval = function(code) {
+
+        if (window.execScript) {
+            window.execScript(code);
+            return;
+        }
+
+        eval.call(null, code);
+    }
+
+    /**
+     * gets the local or global options with local ones having higher priority
+     * if no local or global one was found then the default value is given back
+     *
+     * @param {String} configName the name of the configuration entry
+     * @param {String} localOptions the local options root for the configuration myfaces as default marker is added implicitely
+     *
+     * @param {Object} defaultValue
+     *
+     * @return either the config entry or if none is given the default value
+     */
+    myfaces._impl._util._Utils.getLocalOrGlobalConfig = function(localOptions, configName, defaultValue) {
+        /*use(myfaces._impl._util)*/
+        var _LangUtils = myfaces._impl._util._LangUtils;
+
+        var globalOption = myfaces._impl._util._Utils.getGlobalConfig(configName, defaultValue);
+        if(!_LangUtils.exists(localOptions, "myfaces") || !_LangUtils.exists(localOptions.myfaces,configName)) {
+            return globalOption;
+        }
+        return localOptions.myfaces[configName];
+    };
+
+    myfaces._impl._util._Utils.browserDetection();
+}

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js?rev=780394&r1=780393&r2=780394&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf_impl.js Sun May 31 09:32:13 2009
@@ -46,7 +46,7 @@
      * [STATIC] constants
      */
 
-    myfaces._impl.core._jsfImpl._PROP_PARTIAL_SOURCE = "javax.faces.partial.source";
+    myfaces._impl.core._jsfImpl._PROP_PARTIAL_SOURCE = "javax.faces.source";
     myfaces._impl.core._jsfImpl._PROP_VIEWSTATE = "javax.faces.ViewState";
     myfaces._impl.core._jsfImpl._PROP_AJAX = "javax.faces.partial.ajax";
     myfaces._impl.core._jsfImpl._PROP_EXECUTE = "javax.faces.partial.execute";
@@ -111,9 +111,9 @@
         if ('undefined' == typeof( element ) || null == element) {
             throw new Exception("jsf.ajax, element must be set!");
         }
-        if (!JSF2Utils.isString(element) && !(element instanceof Node)) {
-            throw new Exception("jsf.ajax, element either must be a string or a dom node");
-        }
+//        if (!JSF2Utils.isString(element) && !(element instanceof Node)) {
+//            throw new Exception("jsf.ajax, element either must be a string or a dom node");
+//        }
 
         element = JSF2Utils.byId(element);
         if ('undefined' == typeof element || null == element) {
@@ -196,22 +196,18 @@
         /**
          * fetch the parent form
          */
-
-        //TODO check if we can add this to the context
-
         var sourceForm = myfaces._impl._util._Utils.getParent(null, ajaxContext, element, "form");
 
         if ('undefined' == typeof sourceForm || null == sourceForm) {
             sourceForm = document.forms[0];
         }
 
-        /*
-         * binding contract the javax.faces.partial.source must be
-         * set according to the december 2008 preview
+        /**
+         * binding contract the javax.faces.source must be set 
          */
         passThroughArguments[myfaces._impl.core._jsfImpl._PROP_PARTIAL_SOURCE] = element.id;
 
-        /*
+        /**
          * javax.faces.partial.ajax must be set to true
          */
         passThroughArguments[myfaces._impl.core._jsfImpl._PROP_AJAX] = true;
@@ -300,6 +296,8 @@
         eventData.type = myfaces._impl.core._jsfImpl._MSG_TYPE_ERROR;
 
         eventData.name = name;
+        eventData.serverErrorName = serverErrorName;
+        eventData.serverErrorMessage = serverErrorMessage;
         try {
             eventData.source = context.source;
             eventData.responseXML = request.responseXML;
@@ -347,7 +345,7 @@
                 eventData.responseText = request.responseText;
                 eventData.responseCode = request.status;
             } catch (e) {
-                jsf.ajax.sendError(request, context, myfaces._impl.core._jsfImpl._ERROR_CLIENT_ERROR, "ErrorRetrievingResponse",
+            	myfaces.ajax.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);
             }
         }
@@ -385,7 +383,7 @@
    * implementation of the external chain function
    * moved into the impl
    *
-   * according to the ri the source will bhe the scope
+   * according to the ri the source will be the scope
    * for the functions the event will be the object passed
    * @param {Object} source the source which also becomes
    * the scope for the calling function (not sure if this is correct however
@@ -420,17 +418,14 @@
             if('function' == typeof arguments[loop]) {    
                  retVal = arguments[loop].call(thisVal, param);
             } else {
-                 retVal = (new Function("evt", arguments[loop])).call(thisVal, param);
+	            retVal = new Function("event", arguments[loop]).call(thisVal, param);   
             }
             //now if one function returns null in between we stop the execution of the cycle
             //here
             if('undefined' != typeof retVal && retVal === false) return;
         }
-   };
+   }
     
-    //for debugging purposes only remove before going into production
-    //should be removed automatically by the build process!!!
-    ;;var myfaces_JSFDebug = new myfaces._impl.core._jsfImpl();
-
-
+    // singleton
+    myfaces.ajax = new myfaces._impl.core._jsfImpl();
 }

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.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/_AjaxRequest.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js Sun May 31 09:32:13 2009
@@ -1,135 +1,161 @@
-/*
- * 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.10 $ $Date: 2009/04/23 11:03:09 $
- *
- */
-
-_reserveMyfacesNamespaces();
-
-if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxRequest")) {
-
-    /**
-     * Constructor
-     * @param {HtmlElement} source - Item that triggered the request
-     * @param {Html Form} sourceForm - Form containing source
-     * @param {Map} context - AJAX context
-     * @param {Map} passThough - parameters to pass through to the server (execute/render)
-     */
-    myfaces._impl.xhrCore._AjaxRequest = function(source, sourceForm, context, passThrough) {
-        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxRequest", this.alarmThreshold);
-        try {
-            this.m_contentType = "application/x-www-form-urlencoded";
-            this.m_source = source;
-            this.m_xhr = null;
-            // myfaces parameters
-            this.m_partialIdsArray = null;
-            var errorlevel = 'NONE';
-            this.m_queuesize = -1;
-
-            /*namespace remapping for readability*/
-            var _Utils = myfaces._impl._util._Utils;
-            var _LangUtils = myfaces._impl._util._LangUtils;
-
-            if (_Utils.getLocalOrGlobalConfig(context,"errorlevel", null) != null) {
-                errorlevel = context.myfaces.errorlevel;
-            }
-            if (_Utils.getLocalOrGlobalConfig(context,"queuesize", null) != null) {
-                this.m_queuesize = context.myfaces.queuesize;
-            }
-            if (_Utils.getLocalOrGlobalConfig(context,"pps", null) != null
-                &&  _LangUtils.exists(passThrough,myfaces._impl.core._jsfImpl._PROP_EXECUTE)
-                && passThrough[myfaces._impl.core._jsfImpl._PROP_EXECUTE].length > 0) {
-                this.m_partialIdsArray = passThrough[myfaces._impl.core._jsfImpl._PROP_EXECUTE].split(" ");
-            }
-        
-            this.m_context = context;
-            this.m_response = new myfaces._impl.xhrCore._AjaxResponse(errorlevel);
-            this.m_ajaxUtil = new myfaces._impl.xhrCore._AjaxUtils(errorlevel);
-            this.m_sourceForm = sourceForm;
-            this.m_passThrough = passThrough;
-            this.m_requestParameters = this.getViewState();
-            for (var key in this.m_passThrough) {
-                this.m_requestParameters = this.m_requestParameters +
-                "&" + encodeURIComponent(key) +
-                "=" + encodeURIComponent(this.m_passThrough[key]);
-            }
-        } catch (e) {
-            this.m_exception.throwError(null, context, "Ctor", e);
-        }
-    };
-
-    /**
-     * Sends an Ajax request
-     * @param {RequestQueue} requestQueue - Queue object to trigger next request
-     */
-
-    myfaces._impl.xhrCore._AjaxRequest.prototype.send = function() {
-        try {
-            this.m_xhr = this.m_ajaxUtil.getXHRObject();
-            
-            this.m_xhr.open("POST", this.m_sourceForm.action, true);
-            this.m_xhr.setRequestHeader("Content-Type", this.m_contentType);
-            this.m_xhr.setRequestHeader("Faces-Request", "partial/ajax");
-            this.m_xhr.onreadystatechange = myfaces._impl.xhrCore._AjaxRequestQueue.handleCallback;
-
-            jsf.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_BEGIN);
-            this.m_xhr.send(this.m_requestParameters);
-        } catch (e) {
-            this.m_exception.throwError(this.m_xhr, this.m_context, "send", e);
-        }
-    };
-
-    /**
-     * Callback method to process the Ajax response
-     * triggered by RequestQueue
-     */
-    myfaces._impl.xhrCore._AjaxRequest.prototype.requestCallback = function() {
-        var READY_STATE_DONE = 4;
-        try {
-
-            if (this.m_xhr.readyState == READY_STATE_DONE) {
-                if (this.m_xhr.status >= 200 || this.m_xhr.status < 300) {
-                    jsf.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
-                    jsf.ajax.response(this.m_xhr, this.m_context);
-                    jsf.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_SUCCESS);
-                    myfaces._impl.xhrCore._AjaxRequestQueue.queue.processQueue();
-                } else {
-                    jsf.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
-                    jsf.ajax.sendError(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._ERROR_HTTPERROR,
-                        myfaces._impl.core._jsfImpl._ERROR_HTTPERROR, "Request failed with status " + this.m_xhr.status
-                        + " and reason " + this.getHtmlStatusText());
-                }
-            }
-        } catch (e) {
-            this.m_exception.throwError(this.m_xhr, this.m_context, "requestCallback", e);
-        }
-    }
-
-    /**
-     * Spec. 13.3.1
-     * Collect and encode input elements.
-     * Additionally the hidden element javax.faces.ViewState
-     * @return {String} - Concatenated String of the encoded input elements
-     * 			and javax.faces.ViewState element
-     */
-    myfaces._impl.xhrCore._AjaxRequest.prototype.getViewState = function() {
-        return this.m_ajaxUtil.processUserEntries(this.m_xhr, this.m_context, this.m_source,
-            this.m_sourceForm, this.m_partialIdsArray);
-    }
-
-
-}
+/*
+ * 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.4 $ $Date: 2009/05/31 09:16:44 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxRequest")) {
+
+    /**
+     * Constructor
+     * @param {HtmlElement} source - Item that triggered the request
+     * @param {Html Form} sourceForm - Form containing source
+     * @param {Map} context - AJAX context
+     * @param {Map} passThough - parameters to pass through to the server (execute/render)
+     */
+    myfaces._impl.xhrCore._AjaxRequest = function(source, sourceForm, context, passThrough) {
+        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxRequest", this.alarmThreshold);
+        try {
+            this.m_contentType = "application/x-www-form-urlencoded";
+            this.m_source = source;
+            this.m_xhr = null;
+            // myfaces parameters
+            this.m_partialIdsArray = null;
+            var errorlevel = 'NONE';
+            this.m_queuesize = -1;
+
+            /*namespace remapping for readability*/
+            var _Utils = myfaces._impl._util._Utils;
+            var _LangUtils = myfaces._impl._util._LangUtils;
+
+            if (_Utils.getLocalOrGlobalConfig(context,"errorlevel", null) != null) {
+                errorlevel = context.myfaces.errorlevel;
+            }
+            if (_Utils.getLocalOrGlobalConfig(context,"queuesize", null) != null) {
+                this.m_queuesize = context.myfaces.queuesize;
+            }
+            if (_Utils.getLocalOrGlobalConfig(context,"pps", null) != null
+                &&  _LangUtils.exists(passThrough,myfaces._impl.core._jsfImpl._PROP_EXECUTE)
+                && passThrough[myfaces._impl.core._jsfImpl._PROP_EXECUTE].length > 0) {
+                this.m_partialIdsArray = passThrough[myfaces._impl.core._jsfImpl._PROP_EXECUTE].split(" ");
+            }
+            if (_Utils.getLocalOrGlobalConfig(context,"timeout", null) != null) {
+            	this.m_timeout = context.myfaces.timeout;
+            }
+            if (_Utils.getLocalOrGlobalConfig(context,"delay", null) != null) {
+            	this.m_delay = context.myfaces.delay;
+            }
+            this.m_context = context;
+            this.m_response = new myfaces._impl.xhrCore._AjaxResponse(errorlevel);
+            this.m_ajaxUtil = new myfaces._impl.xhrCore._AjaxUtils(errorlevel);
+            this.m_sourceForm = sourceForm;
+            this.m_passThrough = passThrough;
+            this.m_requestParameters = this.getViewState();
+            for (var key in this.m_passThrough) {
+                this.m_requestParameters = this.m_requestParameters +
+                "&" + encodeURIComponent(key) +
+                "=" + encodeURIComponent(this.m_passThrough[key]);
+            }
+        } catch (e) {
+            this.m_exception.throwError(null, context, "Ctor", e);
+        }
+    };
+
+    /**
+     * Sends an Ajax request
+     * @param {RequestQueue} requestQueue - Queue object to trigger next request
+     */
+    myfaces._impl.xhrCore._AjaxRequest.prototype.send = function() {
+        try {
+            this.m_xhr = this.m_ajaxUtil.getXHRObject();
+            
+            this.m_xhr.open("POST", this.m_sourceForm.action, true);
+            this.m_xhr.setRequestHeader("Content-Type", this.m_contentType);
+            this.m_xhr.setRequestHeader("Faces-Request", "partial/ajax");
+            this.m_xhr.onreadystatechange = myfaces._impl.xhrCore._AjaxRequestQueue.handleCallback;
+
+            myfaces.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_BEGIN);
+            this.m_xhr.send(this.m_requestParameters);
+            if ('undefined' != typeof this.m_timeout) {
+	            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();
+		            		}
+	            		} catch (e) {
+	            			// don't care about exceptions here
+	            		}
+	            	}, this.m_timeout);
+            }
+        } catch (e) {
+            this.m_exception.throwError(this.m_xhr, this.m_context, "send", e);
+        }
+    };
+
+    /**
+     * Callback method to process the Ajax response
+     * triggered by RequestQueue
+     */
+    myfaces._impl.xhrCore._AjaxRequest.prototype.requestCallback = function() {
+        var READY_STATE_DONE = 4;
+        try {
+
+            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);
+                    myfaces._impl.xhrCore._AjaxRequestQueue.queue.processQueue();
+                } else {
+                	myfaces.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_COMPLETE);
+            		var errorText;
+                	try {
+                		errorText = "Request failed";
+                		if (this.m_xhr.status) {
+                			errorText += "with status " + this.m_xhr.status;
+                			if (this.m_xhr.statusText) {
+                				errorText += " and reason " + this.m_xhr.statusText;
+                			}
+                		}
+                	} catch (e) {
+                		errorText = "Request failed with unknown status";
+                	}
+                	myfaces.ajax.sendError(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._ERROR_HTTPERROR,
+                        myfaces._impl.core._jsfImpl._ERROR_HTTPERROR, errorText);
+                }
+            }
+        } catch (e) {
+            this.m_exception.throwError(this.m_xhr, this.m_context, "requestCallback", e);
+        }
+    }
+
+    /**
+     * Spec. 13.3.1
+     * Collect and encode input elements.
+     * Additionally the hidden element javax.faces.ViewState
+     * @return {String} - Concatenated String of the encoded input elements
+     * 			and javax.faces.ViewState element
+     */
+    myfaces._impl.xhrCore._AjaxRequest.prototype.getViewState = function() {
+        return this.m_ajaxUtil.processUserEntries(this.m_xhr, this.m_context, this.m_source,
+            this.m_sourceForm, this.m_partialIdsArray);
+    }
+}

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.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/_AjaxRequestQueue.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequestQueue.js Sun May 31 09:32:13 2009
@@ -1,92 +1,120 @@
-/*
- * 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, "_AjaxRequestQueue")) {
-
-    /**
-     * Constructor
-     */
-    myfaces._impl.xhrCore._AjaxRequestQueue = function() {
-        this.m_request = null;
-        this.m_queuedRequests = [];
-        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxRequestQueue", "NONE");
-    };
-
-    /**
-     * [STATIC PROPERTIES]
-     */
-    myfaces._impl.xhrCore._AjaxRequestQueue.queue = new myfaces._impl.xhrCore._AjaxRequestQueue();
-
-    /**
-     * [STATIC]
-     * provides api callback
-     */
-    myfaces._impl.xhrCore._AjaxRequestQueue.handleCallback = function() {
-        if (myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request != null) {
-            myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.requestCallback();
-        } else {
-            myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_exception.throwWarning
-            (null, null, "doRequestCallback", "No request object available");
-        }
-    };
-
-    /**
-     * send a reuest or keeps it in a queue
-     * @param {myfaces._impl.xhrCore._AjaxRequest} request - request to send
-     */
-    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.queueRequest = function(request) {
-        if (this.m_request == null) {
-            this.m_request = request;
-            this.m_request.send();
-        } else {
-            this.m_queuedRequests.push(request);
-            if (request.m_queuesize > -1 && request.m_queuesize < this.m_queuedRequests.length)
-                this.m_queuedRequests.shift();
-        }
-    };
-
-    /**
-     * process queue, send request, if exists
-     */
-    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.processQueue = function() {
-        if (this.m_queuedRequests.length > 0) {
-            // Using Javascripts build-in queue capabilities here!
-            // JSF RI is using Delayed Shift Queue (DSQ), which starts to outperform the build-in queue
-            // when queue size exceeds ~10 requests (http://safalra.com/web-design/javascript/queues/).
-            // With JSF Ajax the queue will hardly ever reach this size.
-            this.m_request = this.m_queuedRequests.shift();
-            this.m_request.send();
-        } else {
-            this.m_request = null;
-        }
-    };
-
-    /**
-     * cleanup queue
-     */
-    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.clearQueue = function() {
-        this.m_request = null;
-        this.m_queuedRequest = null;
-        this.m_requestPending = false;
-    };
-
+/*
+ * 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.3 $ $Date: 2009/05/31 09:16:44 $
+ *
+ */
+
+_reserveMyfacesNamespaces();
+
+if (!myfaces._impl._util._LangUtils.exists(myfaces._impl.xhrCore, "_AjaxRequestQueue")) {
+
+    /**
+     * Constructor
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue = function() {
+        this.m_request = null;
+        this.m_queuedRequests = [];
+        this.m_exception = new myfaces._impl.xhrCore._Exception("myfaces._impl.xhrCore._AjaxRequestQueue", "NONE");
+    };
+
+    /**
+     * [STATIC PROPERTIES]
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue.queue = new myfaces._impl.xhrCore._AjaxRequestQueue();
+
+    /**
+     * [STATIC]
+     * provides api callback
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue.handleCallback = function() {
+        if (myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request != null) {
+            myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_request.requestCallback();
+        } else {
+            myfaces._impl.xhrCore._AjaxRequestQueue.queue.m_exception.throwWarning
+            (null, null, "doRequestCallback", "No request object available");
+        }
+    };
+
+    /**
+     * delay request, then call queueNow
+     * @param {myfaces._impl.xhrCore._AjaxRequest} request - request to send
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.queueRequest = function(request) {
+        if (typeof request.m_delay == "number") {
+        	this.clearDelayTimeout();
+            this.delayTimeoutId = window.setTimeout(
+            	function() {
+            		myfaces._impl.xhrCore._AjaxRequestQueue.queue.clearDelayTimeout();
+                	myfaces._impl.xhrCore._AjaxRequestQueue.queue.queueNow(request);
+            	}, request.m_delay);
+        } else {
+        	this.queueNow(request);
+        }
+    };
+
+    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.clearDelayTimeout = function() {
+		try {
+			if (typeof this.delayTimeoutId == "number") {
+				window.clearTimeout(this.delayTimeoutId);
+				delete this.delayTimeoutId;
+			}
+		} catch (e) {
+			// already timed out
+		}
+    }
+    
+    /**
+     * send a request or keep it in a queue
+     * @param {myfaces._impl.xhrCore._AjaxRequest} request - request to send
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.queueNow = function(request) {
+        if (this.m_request == null) {
+            this.m_request = request;
+            this.m_request.send();
+        } else {
+            this.m_queuedRequests.push(request);
+            if (request.m_queuesize > -1 && request.m_queuesize < this.m_queuedRequests.length)
+                this.m_queuedRequests.shift();
+        }
+    };
+
+    /**
+     * process queue, send request, if exists
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.processQueue = function() {
+        if (this.m_queuedRequests.length > 0) {
+            // Using Javascripts build-in queue capabilities here!
+            // JSF RI is using Delayed Shift Queue (DSQ), which starts to outperform the build-in queue
+            // when queue size exceeds ~10 requests (http://safalra.com/web-design/javascript/queues/).
+            // With JSF Ajax the queue will hardly ever reach this size.
+            this.m_request = this.m_queuedRequests.shift();
+            this.m_request.send();
+        } else {
+            this.m_request = null;
+        }
+    };
+
+    /**
+     * cleanup queue
+     */
+    myfaces._impl.xhrCore._AjaxRequestQueue.prototype.clearQueue = function() {
+        this.m_request = null;
+        this.m_queuedRequest = null;
+        this.m_requestPending = false;
+    };
+
 }
\ No newline at end of file



Mime
View raw message