You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/06/25 14:11:09 UTC
svn commit: r957910 - in
/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl:
_util/_Dom.js _util/_Lang.js _util/_Queue.js core/_Runtime.js
core/jsf-uncompressed.js xhrCore/_AjaxResponse.js xhrCore/_AjaxUtils.js
Author: werpu
Date: Fri Jun 25 12:11:08 2010
New Revision: 957910
URL: http://svn.apache.org/viewvc?rev=957910&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2773
Modified:
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf-uncompressed.js
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js Fri Jun 25 12:11:08 2010
@@ -65,17 +65,18 @@ myfaces._impl.core._Runtime.singletonExt
* @param {|Node|} item
*/
runScripts: function(item) {
-
var execScrpt = myfaces._impl._util._Lang.hitch(this, function(item) {
if (item.tagName && item.tagName.toLowerCase() == 'script') {
-
- if (typeof item.getAttribute('src') != 'undefined'
- && item.getAttribute('src') != null
- && item.getAttribute('src').length > 0) {
- // external script auto eval
- //TODO fix the encoding here, we have to assume the src is the same encoding as the document
- //or enforce auto
- myfaces._impl.core._Runtime.loadScriptEval(item.getAttribute('src'), item.getAttribute('type'), false, "UTF-8");
+ var src = item.getAttribute('src');
+ if ( 'undefined' != typeof src
+ && null != src
+ && src.length > 0
+ ) {
+ //we have to move this into an inner if because chrome otherwise chokes
+ //due to changing the and order instead of relying on left to right
+ if ((src.indexOf("ln=scripts") == -1 && src.indexOf("ln=javax.faces") == -1) || (src.indexOf("/jsf.js") == -1
+ && src.indexOf("/jsf-uncompressed.js") == -1))
+ myfaces._impl.core._Runtime.loadScriptEval(src, item.getAttribute('type'), false, "UTF-8");
} else {
// embedded script auto eval
var test = item.text;
@@ -704,7 +705,7 @@ myfaces._impl.core._Runtime.singletonExt
//special ie quirks handling for opacity
var opacityVal = Math.max(100, Math.round(parseFloat(keyVal[1]) * 10));
- node.style.setAttribute("filter", "alpha(opacity=" + opacityVal + ")");
+ node.style.setAttribute("arrFilter", "alpha(opacity=" + opacityVal + ")");
//if you need more hacks I would recommend
//to use the class attribute and conditional ie includes!
} else if (keyVal[0] != "") {
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js Fri Jun 25 12:11:08 2010
@@ -12,7 +12,7 @@
* 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.
-*/
+ */
/*
@@ -38,14 +38,14 @@ myfaces._impl.core._Runtime.singletonDel
if (!namespace || !this.isString(namespace)) {
throw Error("_Lang.fetchNamespace namespace must be of type String");
}
- return this._callDelegate("fetchNamespace",namespace);
+ return this._callDelegate("fetchNamespace", namespace);
},
reserveNamespace : function(namespace) {
if (!this.isString(namespace)) {
throw Error("_Lang.reserveNamespace namespace must be of type String");
}
- return this._callDelegate("reserveNamespace",namespace);
+ return this._callDelegate("reserveNamespace", namespace);
//return this._RT.reserveNamespace(namespace);
},
@@ -53,7 +53,7 @@ myfaces._impl.core._Runtime.singletonDel
if (!this.isString(code)) {
throw Error("_Lang.globalEval code must be of type String");
}
- return this._callDelegate("globalEval",code);
+ return this._callDelegate("globalEval", code);
//return this._RT.globalEval(code);
},
@@ -75,21 +75,6 @@ myfaces._impl.core._Runtime.singletonDel
},
/**
- * check if an element exists in the root
- */
- /*exists : function(root, subNamespace) {
- return this._RT.exists(root, subNamespace);
- },*/
-
- /**
- @see this._RT.extendClass
- */
- /*singletonExtendClass : function(newClass, extendsClass, functionMap, inherited) {
- return this._RT.singletonExtendClass(newClass, extendsClass, functionMap, inherited);
- },*/
-
-
- /**
* equalsIgnoreCase, case insensitive comparison of two strings
*
* @param source
@@ -112,8 +97,8 @@ myfaces._impl.core._Runtime.singletonDel
@see this._RT.extendClass
*/
/*extendClass : function(newClass, extendsClass, functionMap, inherited) {
- return this._RT.extendClass(newClass, extendsClass, functionMap, inherited);
- },*/
+ return this._RT.extendClass(newClass, extendsClass, functionMap, inherited);
+ },*/
//core namespacing and inheritance done, now to the language extensions
@@ -396,19 +381,7 @@ myfaces._impl.core._Runtime.singletonDel
return this.isString(theType) ? probe == typeof theType : probe instanceof theType;
},
- /**
- * onload wrapper for chaining the onload cleanly
- * @param func the function which should be added to the load
- * chain (note we cannot rely on return values here, hence jsf.util.chain will fail)
- */
- addOnLoad: function(func) {
- var oldonload = window.onload;
- window.onload = (!this.assertType(window.onload, "function")) ? func : function() {
- oldonload();
- func();
- };
- },
-
+
objToArray: function(obj, offset, pack) {
//since offset is numeric we cannot use the shortcut due to 0 being false
@@ -431,63 +404,108 @@ myfaces._impl.core._Runtime.singletonDel
},
- //not yet used
/**
- * attaches a standard iterator if
- * the collection does not have one already
- *
- * @param inColl
- */
- /* collection : function (inColl) {
- var _coll = inColl;
-
- if (_coll instanceof Array) {
- if (!_coll.each) {
- _coll.each = function(closure) {
- for (var cnt = 0; cnt < _coll.length; cnt++) {
- //if(caller.this) {
- // closure.apply(caller.this, [cnt, _coll[cnt]]);
- //} else {
- closure(cnt, _coll[cnt]);
- //}
- }
- }
+ * foreach implementation utilizing the
+ * ECMAScript wherever possible
+ * with added functionality
+ *
+ * @param arr the array to filter
+ * @param func the closure to apply the function to, with the syntax defined by the ecmascript functionality
+ * function (element<,key, array>)
+ * @param startPos (optional) the starting position
+ * @param scope (optional) the scope to apply the closure to
+ */
+ arrForEach: function(arr, func /*startPos, scope*/) {
+ var startPos = Number(arguments[2]) || 0;
+ var thisObj = arguments[3];
+
+ //check for an existing foreach mapping on array prototypes
+ if (Array.prototype.forEach) {
+ (startPos) ? arr.slice(startPos).forEach(func, thisObj) : arr.forEach(func, thisObj);
+ } else {
+ startPos = (startPos < 0)? Math.ceil(startPos): Math.floor(startPos);
+ if (typeof func != "function") {
+ throw new TypeError();
}
- if (!_coll.filter) {
- _coll.filter = function(closure) {
-
- var retVal = [];
- for (var cnt = 0; cnt < _coll.length; cnt++) {
- var elem = closure(_coll[cnt]);
- if (closure(cnt, elem)) {
- retVal.push(elem)
- }
- }
+ for (var cnt = 0; cnt < arr.length; cnt++) {
+ if (thisObj) {
+ func.call(thisObj, arr[cnt], cnt, arr);
+ } else {
+ func(arr[cnt], cnt, arr);
}
}
+ }
+ },
+
+ /**
+ * foreach implementation utilizing the
+ * ECMAScript wherever possible
+ * with added functionality
+ *
+ * @param arr the array to filter
+ * @param func the closure to apply the function to, with the syntax defined by the ecmascript functionality
+ * function (element<,key, array>)
+ * @param startPos (optional) the starting position
+ * @param scope (optional) the scope to apply the closure to
+ *
+ */
+ arrFilter: function(arr, func /*startPos, scope*/) {
+ var startPos = Number(arguments[2]) || 0;
+ var thisObj = arguments[3];
+
+ //check for an existing foreach mapping on array prototypes
+ if (Array.prototype.filter) {
+ return ((startPos) ? arr.slice(startPos).filter(func, thisObj) : arr.filter(func, thisObj));
} else {
- if (!_coll.each) {
- _coll.each = function(closure) {
- for (var key in _coll.length) {
- closure(key, _coll[key]);
- }
- }
+ if (typeof func != "function") {
+ throw new TypeError();
}
- if (!_coll.filter) {
- _coll.filter = function(closure) {
- var retVal = [];
- for (var key in _coll.length) {
- var elem = closure(_coll[key]);
- if (closure(key, elem)) {
- retVal.push(elem)
- }
- }
+ var ret = [];
+ startPos = (startPos < 0)? Math.ceil(startPos): Math.floor(startPos);
+
+ for (var cnt = startPos; cnt < arr.length; cnt++) {
+ if (thisObj) {
+ var elem = arr[cnt];
+ if (func.call(thisObj, elem, cnt, arr)) ret.push(elem);
+ } else {
+ var elem = arr[cnt];
+ if (func(arr[cnt], cnt, arr)) ret.push(elem);
}
}
+ }
+ },
+ /**
+ * adds a EcmaScript optimized indexOf to our mix,
+ * checks for the presence of an indexOf functionality
+ * and applies it, otherwise uses a fallback to the hold
+ * loop method to determine the index
+ *
+ * @param arr the array
+ * @param element the index to search for
+ */
+ arrIndexOf: function(arr, element /*fromIndex*/) {
+ if(!arr) return -1;
+ var pos = Number(arguments[2]) || 0;
+
+ if(Array.prototype.indexOf) {
+ return arr.indexOf(element, pos);
}
- },*/
+ //var cnt = this._space;
+ var len = arr.length;
+ pos = (pos < 0)? Math.ceil(pos): Math.floor(pos);
+
+ //if negative then it is taken from as offset from the length of the array
+ if(pos < 0) {
+ pos += len;
+ }
+ while (pos < len && arr[pos] !== element) {
+ pos++;
+ }
+ return (pos < len) ? pos : -1;
+ },
+
/**
* helper to automatically apply a delivered arguments map or array
@@ -558,5 +576,5 @@ myfaces._impl.core._Runtime.singletonDel
ret.push(delimiter);
return ret.join("");
}
-
+
});
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js Fri Jun 25 12:11:08 2010
@@ -12,7 +12,7 @@
* 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.
-*/
+ */
/** @namespace myfaces._impl._util._Queue */
myfaces._impl.core._Runtime.extendClass("myfaces._impl._util._Queue", Object, {
@@ -26,7 +26,7 @@ myfaces._impl.core._Runtime.extendClass(
constructor_: function() {
this._q = [];
-
+ this._Lang = myfaces._impl._util._Lang;
},
length: function() {
@@ -111,16 +111,7 @@ myfaces._impl.core._Runtime.extendClass(
* @param closure a closure which processes the element
*/
each: function(closure) {
- //we have a browser optimized ecmascript version present
- //which again is all newer browsers except ie
- if(Array.prototype.forEach) {
- return (this._space)? this._q.slice(this._space).forEach( closure ): this._q.forEach( closure ) ;
- }
-
- var len = this._q.length;
- for (var cnt = this._space; cnt < len; cnt++) {
- closure(this._q[cnt]);
- }
+ this._Lang.arrForEach(this._q, closure, this._space);
},
/**
@@ -131,33 +122,12 @@ myfaces._impl.core._Runtime.extendClass(
*
* @return an array of filtered queue entries
*/
- filter: function(closure) {
- var ret = [];
- var len = this._q.length;
-
- //we have a browser optimized ecmascript version present
- //which again is all newer browsers except ie
- if(Array.prototype.filter) {
- return (this._space)? this._q.slice(this._space).filter( closure ): this._q.filter( closure );
- }
-
- for (var cnt = this._space; cnt < len; cnt++) {
- if (closure(this._q[cnt])) {
- ret.push(this._q[cnt]);
- }
- }
- return ret;
+ arrFilter: function(closure) {
+ return this._Lang.arrFilter(this._q, closure, this._space);
},
indexOf: function(element) {
- var cnt = this._space;
- var len = this._q.length;
- while (cnt < len && this._q[cnt] !== element) {
- cnt += 1;
- }
- /*found*/
- cnt = (cnt < len) ? cnt : -1;
- return cnt;
+ return this._Lang.indexOf(this._q, element);
},
cleanup: function() {
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js Fri Jun 25 12:11:08 2010
@@ -12,7 +12,7 @@
* 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.
-*/
+ */
/**
@@ -277,6 +277,7 @@ if (!myfaces._impl.core._Runtime) {
return (!_this.exists(localOptions, "myfaces." + configName)) ? _this.getGlobalConfig(configName, defaultValue) : localOptions.myfaces[configName];
};
+
/**
* encapsulated xhr object which tracks down various implementations
@@ -358,9 +359,9 @@ if (!myfaces._impl.core._Runtime) {
//the rest can be finely served with body
var d = this.browser;
var position = "head"
- if(!d.isIE || d.isIE >= 8) {
- position = document.getElementsByTagName("body").length ? "body" : "head";
- }
+ //if(!d.isIE || d.isIE >= 8) {
+ // position = document.getElementsByTagName("body").length ? "body" : "head";
+ //}
try {
var holder = document.getElementsByTagName(position)[0];
@@ -379,12 +380,17 @@ if (!myfaces._impl.core._Runtime) {
if (defer) {
script.defer = defer;
}
- holder.appendChild(script);
+
+ //fix for the white page issue
+ // if(this.browser.isIE && this.browser.isIE < 7) {
+ // holder.insertBefore( script, holder.firstChild );
+ // holder.removeChild( script );
+ // } else {
+ holder.appendChild(script);
+ // }
+
} catch (e) {
- //webkit based browsers and probably
- //other standard conforming browsers forbid head manipulation
- //after the head tag being closed
- //we fall back to global eval for those cases
+ //in case of a loading error we retry via eval
return false;
}
@@ -392,8 +398,15 @@ if (!myfaces._impl.core._Runtime) {
};
this.loadScript = function(src, type, defer, charSet) {
- if (!_this.loadScriptByBrowser(src, type, defer, charSet)) {
+ //the chrome engine has a nasty javascript bug which prevents
+ //a correct order of scripts being loaded
+ //if you use script source on the head, we have to revert
+ //to xhr+ globalEval for those
+ if(!_this.browser.isFF) {
_this.loadScriptEval(src, type, defer, charSet);
+ } else {
+ //only firefox keeps the order, sorry ie...
+ _this.loadScriptByBrowser(src, type, defer, charSet)
}
};
@@ -611,7 +624,20 @@ if (!myfaces._impl.core._Runtime) {
}
}
};
-
+
+ /**
+ * onload wrapper for chaining the onload cleanly
+ * @param func the function which should be added to the load
+ * chain (note we cannot rely on return values here, hence jsf.util.chain will fail)
+ */
+ this.addOnLoad = function(func) {
+ var oldonload = window.onload;
+ window.onload = (!this.assertType(window.onload, "function")) ? func : function() {
+ oldonload();
+ func();
+ };
+ };
+
/**
* determines if the embedded scripts have to be evaled manually
* @return true if a browser combination is given which has to
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf-uncompressed.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf-uncompressed.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf-uncompressed.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/jsf-uncompressed.js Fri Jun 25 12:11:08 2010
@@ -12,18 +12,20 @@
* 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.
-*/
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_Lang.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_ExtLang.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_UnitTest.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_Queue.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_ListenerQueue.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_Dom.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_HtmlStripper.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxUtils.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxRequestQueue.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxRequest.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxResponse.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_Transports.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.core:Impl.js']}", null, null, "UTF-8");
-myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.api:jsf.js']}", null, null, "UTF-8");
\ No newline at end of file
+ */
+if (!window.jsf) {
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_Lang.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_ExtLang.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_UnitTest.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_Queue.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_ListenerQueue.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_Dom.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.util:_HtmlStripper.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxUtils.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxRequestQueue.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxRequest.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_AjaxResponse.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.xhrCore:_Transports.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.impl.core:Impl.js']}", null, null, "UTF-8");
+ myfaces._impl.core._Runtime.loadScript("#{resource['org.apache.myfaces.core.api:jsf.js']}", null, null, "UTF-8");
+}
\ No newline at end of file
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Fri Jun 25 12:11:08 2010
@@ -17,9 +17,6 @@
/** @namespace myfaces._impl.xhrCore._AjaxResponse */
myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._AjaxResponse", Object, {
-
-
-
/*partial response types*/
RESP_PARTIAL : "partial-response",
RESP_TYPE_ERROR : "error",
@@ -57,6 +54,9 @@ myfaces._impl.core._Runtime.extendClass(
this._onWarning = onWarning;
this.appliedViewState = null;
+
+ this._Lang = myfaces._impl._util._Lang;
+ this._Dom = myfaces._impl._util._Dom;
},
/**
* uses response to start Html element replacement
@@ -72,7 +72,6 @@ myfaces._impl.core._Runtime.extendClass(
*/
processResponse : function(request, context) {
try {
- var _Lang = myfaces._impl._util._Lang;
var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
// TODO:
@@ -85,7 +84,7 @@ myfaces._impl.core._Runtime.extendClass(
throw Exception("jsf.ajaxResponse: The response cannot be null or empty!");
}
- if (!_Lang.exists(request, "responseXML")) {
+ if (!this._Lang.exists(request, "responseXML")) {
_Impl.sendError(request, context, myfaces._impl.core.Impl.EMPTY_RESPONSE);
return;
}
@@ -94,7 +93,7 @@ myfaces._impl.core._Runtime.extendClass(
//ie6+ keeps the parsing response under xmlContent.parserError
//while the rest of the world keeps it as element under the first node
- if ((_Lang.exists(xmlContent, "parseError.errorCode") && xmlContent.parseError.errorCode != 0) || _Lang.equalsIgnoreCase(xmlContent.firstChild.tagName, "parsererror")) {
+ if ((this._Lang.exists(xmlContent, "parseError.errorCode") && xmlContent.parseError.errorCode != 0) || this._Lang.equalsIgnoreCase(xmlContent.firstChild.tagName, "parsererror")) {
//TODO improve error name and message sending here
_Impl.sendError(request, context, myfaces._impl.core.Impl.MALFORMEDXML);
@@ -155,42 +154,48 @@ myfaces._impl.core._Runtime.extendClass(
if (null == this.appliedViewState) {
return;
}
- /*namespace remapping*/
- var _Dom = myfaces._impl._util._Dom;
// Now update the forms that were not replaced but forced to be updated, because contains child ajax tags
// we should only update forms with view state hidden field. If by some reason, the form was set to be
// updated but the form was replaced, it does not have hidden view state, so later in changeTrace processing the
// view state is updated.
- for (var cnt = 0; cnt < this._updateForms.length; cnt ++) {
- var formToUpdate = this._updateForms[cnt];
- var viewStateField = _Dom.findFormElement(formToUpdate, this.P_VIEWSTATE);
- if (null != viewStateField) {
- _Dom.setAttribute(viewStateField, "value", this.appliedViewState);
- }
+
+ //set the viewstates of all outer forms parents of our updated elements
+ this._Lang.arrForEach(this._updateForms, this._setVSTOuterForm, 0, this);
+
+ //set the viewstate of all forms within our updated elements
+ this._Lang.arrForEach(this._updateElems, this._setVSTInnerForms, 0, this);
+ },
+
+ _setVSTOuterForm: function(elem) {
+ var viewStateField = this._Dom.findFormElement(elem, this.P_VIEWSTATE);
+ if (null != viewStateField) {
+ this._Dom.setAttribute(viewStateField, "value", this.appliedViewState);
}
+ },
+
+ _setVSTInnerForms: function(elem) {
+ var replacedForms = this._Dom.findByTagName(elem, "form", false);
+ this._Lang.arrForEach(replacedForms, this._setVSTInnerForm, 0, this);
+ },
- //note the spec here says clearly it is done, but mojarra not and there is a corner case
- //regarding cross form submits, hence we should check all processed items for embedded forms
- for (var cnt = 0; cnt < this._updateElems.length; cnt ++) {
- var replacementElem = this._updateElems[cnt];
- var replacedForms = myfaces._impl._util._Dom.findByTagName(replacementElem, "form", false);
- for (var formCnt = 0; formCnt < replacedForms.length; formCnt++) {
- //we first have to fetch the real form element because the fragment
- //might be detached in some browser implementations
- var appliedReplacedFrom = document.getElementById(replacedForms[formCnt].id);
- var viewStateField = myfaces._impl._util._Dom.findFormElement(appliedReplacedFrom, this.P_VIEWSTATE);
- //we have to add the viewstate field in case it is not rendered
- //otherwise those forms cannot issue another submit
- if (null == viewStateField) {
- var element = document.createElement("input");
- _Dom.setAttribute(element, "type", "hidden");
- _Dom.setAttribute(element, "name", this.P_VIEWSTATE);
- appliedReplacedFrom.appendChild(element);
+ _setVSTInnerForm: function(elem) {
+ //we first have to fetch the real form element because the fragment
+ //might be detached in some browser implementations
+ var appliedReplacedFrom = document.getElementById(elem.id);
+ var viewStateField = this._Dom.findFormElement(appliedReplacedFrom, this.P_VIEWSTATE);
+
+ //we have to add the viewstate field in case it is not rendered
+ //otherwise those forms cannot issue another submit
+ //if the viewstate field is present we can rely on the viewstate being
+ //at the current state no further updates have to be done
+ if (null == viewStateField) {
+ var element = document.createElement("input");
+ this._Dom.setAttribute(element, "type", "hidden");
+ this._Dom.setAttribute(element, "name", this.P_VIEWSTATE);
+ appliedReplacedFrom.appendChild(element);
- _Dom.setAttribute(element, "value", this.appliedViewState);
- }
- }
+ this._Dom.setAttribute(element, "value", this.appliedViewState);
}
},
@@ -220,7 +225,7 @@ myfaces._impl.core._Runtime.extendClass(
_Impl.sendError(request, context, myfaces._impl.core.Impl.MALFORMEDXML, myfaces._impl.core.Impl.MALFORMEDXML, "Redirect without url");
return false;
}
- redirectUrl = myfaces._impl._util._Lang.trim(redirectUrl);
+ redirectUrl = this._Lang.trim(redirectUrl);
if (redirectUrl == "") {
return false;
}
@@ -238,9 +243,6 @@ myfaces._impl.core._Runtime.extendClass(
* @param node the changes node to be processed
*/
processChanges : function(request, context, node) {
-
- var _Lang = myfaces._impl._util._Lang;
-
var changes = node.childNodes;
//note we need to trace the changes which could affect our insert update or delete
@@ -253,7 +255,7 @@ myfaces._impl.core._Runtime.extendClass(
if (!this.processUpdate(request, context, changes[i])) return false;
break;
case this.CMD_EVAL:
- _Lang.globalEval(changes[i].firstChild.data);
+ this._Lang.globalEval(changes[i].firstChild.data);
break;
case this.CMD_INSERT:
if (!this.processInsert(request, context, changes[i])) return false;
@@ -276,17 +278,21 @@ myfaces._impl.core._Runtime.extendClass(
return true;
},
+ /**
+ * First substep process a pending update tag
+ *
+ * @param request the xhr request object
+ * @param context the context map
+ * @param node the changes node to be processed
+ */
processUpdate : function(request, context, node) {
- /*local namespace remapping*/
- var _Dom = myfaces._impl._util._Dom;
- var _Lang = myfaces._impl._util._Lang;
if (node.getAttribute('id') == this.P_VIEWSTATE) {
//update the submitting forms viewstate to the new value
// The source form has to be pulled out of the CURRENT document first because the context object
// may refer to an invalid document if an update of the entire body has occurred before this point.
var viewStateValue = node.firstChild.nodeValue;
- var sourceForm = _Dom.fuzzyFormDetection(context.source);
+ var sourceForm = this._Dom.fuzzyFormDetection(context.source);
// TODO: After some tests, it was found sourceForm could point to a detached instance, but
// there is no harm if we update it. Below there is a code that check if the node has been
@@ -297,11 +303,11 @@ myfaces._impl.core._Runtime.extendClass(
//if (null != sourceForm) {
// Check if sourceForm is inside the document, or in other words, it was not detached.
// We have to walk to the parent node
- //var _Lang = myfaces._impl._util._Lang;
+ //var this._Lang = myfaces._impl._util.this._Lang;
//var searchClosure = function(parentItem) {
// return parentItem && (parentItem == document);
//};
- //var sourceFormAncestor = _Dom.getFilteredParent(sourceForm, searchClosure);
+ //var sourceFormAncestor = this._Dom.getFilteredParent(sourceForm, searchClosure);
//Is not on the document?
//if (null == sourceFormAncestor)
//{
@@ -317,7 +323,7 @@ myfaces._impl.core._Runtime.extendClass(
/*we check for an element and include a namesearch, but only within the bounds of the committing form*/
var element = null;
try {
- element = _Dom.getElementFromForm(this.P_VIEWSTATE, sourceForm, true, true);
+ element = this._Dom.getElementFromForm(this.P_VIEWSTATE, sourceForm, true, true);
} catch (e) {
//in case of an error here we try an early recovery but throw an error to our error handler
this._onException(request, context, "_AjaxResponse", "processUpdate('javax.faces.ViewState')", e);
@@ -325,13 +331,13 @@ myfaces._impl.core._Runtime.extendClass(
if (null == element) {//no element found we have to append a hidden field
element = document.createElement("input");
- _Dom.setAttribute(element, "type", "hidden");
- _Dom.setAttribute(element, "name", this.P_VIEWSTATE);
+ this._Dom.setAttribute(element, "type", "hidden");
+ this._Dom.setAttribute(element, "name", this.P_VIEWSTATE);
sourceForm.appendChild(element);
}
//viewState cannot have split cdata blocks so we can skip the costlier operation
- _Dom.setAttribute(element, "value", viewStateValue);
+ this._Dom.setAttribute(element, "value", viewStateValue);
}
//note due to a missing spec we have to apply the viewstate as well
//to any form which might be rerendered within the render cycle
@@ -342,7 +348,7 @@ myfaces._impl.core._Runtime.extendClass(
else
{
// response may contain several blocks
- var cDataBlock = _Dom.concatCDATABlocks(node);
+ var cDataBlock = this._Dom.concatCDATABlocks(node);
switch (node.getAttribute('id')) {
case this.P_VIEWROOT:
@@ -377,10 +383,8 @@ myfaces._impl.core._Runtime.extendClass(
},
_pushOperationResult: function(resultNode) {
- var _Dom = myfaces._impl._util._Dom;
- var _Lang = myfaces._impl._util._Lang;
- var pushSubnode = _Lang.hitch(this, function(currNode) {
- var parentForm = _Dom.getParent(currNode, "form");
+ var pushSubnode = this._Lang.hitch(this, function(currNode) {
+ var parentForm = this._Dom.getParent(currNode, "form");
if (null != parentForm)
{
this._updateForms.push(parentForm);
@@ -411,9 +415,6 @@ myfaces._impl.core._Runtime.extendClass(
* @param {String} newData the markup which replaces the old dom node!
*/
_replaceBody : function(request, context, newData) {
-
- var _Dom = myfaces._impl._util._Dom;
-
var parser = new (myfaces._impl.core._Runtime.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
var oldBody = document.getElementsByTagName("body")[0];
@@ -435,7 +436,7 @@ myfaces._impl.core._Runtime.extendClass(
for (var key in parser.tagAttributes) {
var value = parser.tagAttributes[key];
- _Dom.setAttribute(newBody, key, value);
+ this._Dom.setAttribute(newBody, key, value);
}
return returnedElement;
}
@@ -466,14 +467,13 @@ myfaces._impl.core._Runtime.extendClass(
*/
replaceHtmlItem : function(request, context, itemIdToReplace, markup, form) {
try {
- var _Lang = myfaces._impl._util._Lang;
// (itemIdToReplace instanceof Node) is NOT compatible with IE8
- var item = (!_Lang.isString(itemIdToReplace)) ? itemIdToReplace :
- myfaces._impl._util._Dom.getElementFromForm(itemIdToReplace, form);
+ var item = (!this._Lang.isString(itemIdToReplace)) ? itemIdToReplace :
+ this._Dom.getElementFromForm(itemIdToReplace, form);
if (!item) {
throw Error("myfaces._impl.xhrCore._AjaxResponse.replaceHtmlItem: item with identifier " + itemIdToReplace.toString() + " could not be found");
}
- return myfaces._impl._util._Dom.outerHTML(item, markup);
+ return this._Dom.outerHTML(item, markup);
} catch (e) {
this._onException(request, context, "myfaces._impl.xhrCore._AjaxResponse", "replaceHTMLItem", e);
@@ -494,17 +494,15 @@ myfaces._impl.core._Runtime.extendClass(
processInsert : function(request, context, node) {
/*remapping global namespaces for speed and readability reasons*/
- var _Lang = myfaces._impl._util._Lang;
- var _Dom = myfaces._impl._util._Dom;
var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
var insertId = node.getAttribute('id');
var beforeId = node.getAttribute('before');
var afterId = node.getAttribute('after');
- var isInsert = insertId && _Lang.trim(insertId) != "";
- var isBefore = beforeId && _Lang.trim(beforeId) != "";
- var isAfter = afterId && _Lang.trim(afterId) != "";
+ var isInsert = insertId && this._Lang.trim(insertId) != "";
+ var isBefore = beforeId && this._Lang.trim(beforeId) != "";
+ var isAfter = afterId && this._Lang.trim(afterId) != "";
if (!isInsert) {
_Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML, "Error in PPR Insert, id must be present");
@@ -518,10 +516,10 @@ myfaces._impl.core._Runtime.extendClass(
var nodeHolder = null;
var parentNode = null;
- var cDataBlock = _Dom.concatCDATABlocks(node);
+ var cDataBlock = this._Dom.concatCDATABlocks(node);
var replacementFragment;
if (isBefore) {
- beforeId = _Lang.trim(beforeId);
+ beforeId = this._Lang.trim(beforeId);
var beforeNode = document.getElementById(beforeId);
if (!beforeNode) {
_Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML, "Error in PPR Insert, before node of id " + beforeId + " does not exist in document");
@@ -541,11 +539,11 @@ myfaces._impl.core._Runtime.extendClass(
nodeHolder, cDataBlock, null);
if (replacementFragment) {
- this._pushOperationResult(replacementFragment);
+ this._pushOperationResult(replacementFragment);
}
} else {
- afterId = _Lang.trim(afterId);
+ afterId = this._Lang.trim(afterId);
var afterNode = document.getElementById(afterId);
if (!afterNode) {
_Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML, "Error in PPR Insert, after node of id " + afterId + " does not exist in document");
@@ -570,7 +568,6 @@ myfaces._impl.core._Runtime.extendClass(
processDelete : function(request, context, node) {
var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
- var _Dom = myfaces._impl._util._Dom;
var deleteId = node.getAttribute('id');
if (!deleteId) {
@@ -579,17 +576,17 @@ myfaces._impl.core._Runtime.extendClass(
return false;
}
- var item = _Dom.byId(deleteId);
+ var item = this._Dom.byId(deleteId);
if (!item) {
throw Error("_AjaxResponse.processDelete Unknown Html-Component-ID: " + deleteId);
}
- var parentForm = _Dom.getParent(item, "form");
+ var parentForm = this._Dom.getParent(item, "form");
if (null != parentForm)
{
this._updateForms.push(parentForm);
}
- _Dom.deleteItem(item);
+ this._Dom.deleteItem(item);
return true;
}
@@ -600,9 +597,8 @@ myfaces._impl.core._Runtime.extendClass(
//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._Dom.setAttribute(domNode, attribute, value;
+ //myfaces._impl._util.this._Dom.setAttribute(domNode, attribute, value;
- var _Dom = myfaces._impl._util._Dom;
var _Impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
//<attributes id="id of element"> <attribute name="attribute name" value="attribute value" />* </attributes>
@@ -627,7 +623,7 @@ myfaces._impl.core._Runtime.extendClass(
continue;
}
- attrName = myfaces._impl._util._Lang.trim(attrName);
+ attrName = this._Lang.trim(attrName);
/*no value means reset*/
//value can be of boolean value hence full check
if ('undefined' == typeof attrValue || null == attrValue) {
@@ -645,11 +641,11 @@ myfaces._impl.core._Runtime.extendClass(
case this.P_VIEWBODY:
var element = document.getElementsByTagName("body")[0];
- _Dom.setAttribute(element, attrName, attrValue);
+ this._Dom.setAttribute(element, attrName, attrValue);
break;
default:
- _Dom.setAttribute(document.getElementById(elemId), attrName, attrValue);
+ this._Dom.setAttribute(document.getElementById(elemId), attrName, attrValue);
break;
}
Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js?rev=957910&r1=957909&r2=957910&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js Fri Jun 25 12:11:08 2010
@@ -64,10 +64,8 @@ myfaces._impl.core._Runtime.extendClass(
}
//we we might have a trailing ambersant
//https://issues.apache.org/jira/browse/MYFACES-2767
- if(strBuf && strBuf.length) {
- if(strBuf[strBuf.length - 1] == "&") {
- strBuf = strBuf.slice(0, strBuf.length - 1);
- }
+ if(strBuf && strBuf.length && strBuf[strBuf.length - 1] == "&") {
+ strBuf = strBuf.slice(0, strBuf.length - 1);
}
return strBuf.join("");
@@ -107,7 +105,8 @@ myfaces._impl.core._Runtime.extendClass(
};
var nodes = _Dom.findAll(node, nodeFilter, true);
-
+ //TODO drag the encodeElement in the nodeFilter so that
+ //we have the entire processing in one loop
if (nodes) {
for (var cnt = 0; cnt < nodes.length; cnt++) {
this.encodeElement(nodes[cnt], strBuf);