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/20 22:27:35 UTC
svn commit: r956408 - in
/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl:
_util/_Dom.js xhrCore/_AjaxResponse.js
Author: werpu
Date: Sun Jun 20 20:27:34 2010
New Revision: 956408
URL: http://svn.apache.org/viewvc?rev=956408&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2763
Fixup for the replacement in the dom, it now works as well on multiple nodes instead of just one, the code still is somewhat ugly, but I will clean it up later.
The fix is closely related to:
https://issues.apache.org/jira/browse/MYFACES-2762
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/xhrCore/_AjaxResponse.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=956408&r1=956407&r2=956408&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 Sun Jun 20 20:27:34 2010
@@ -142,7 +142,8 @@ myfaces._impl.core._Runtime.singletonExt
if (!markup) {
throw Error("myfaces._impl._util._Dom.outerHTML: markup must be passed down");
}
- markup = myfaces._impl._util._Lang.trim(markup);
+ var _Lang = myfaces._impl._util._Lang;
+ markup = _Lang.trim(markup);
if (markup !== "") {
var evalNode = null;
@@ -166,7 +167,8 @@ myfaces._impl.core._Runtime.singletonExt
parentNode = item.parentNode;
- evalNode = fragment.childNodes[0];
+ //evalNode = fragment.childNodes[0];
+ evalNode = Lang.objToArray(fragment.childNodes);
parentNode.replaceChild(fragment, item);
}
} else {
@@ -175,7 +177,7 @@ myfaces._impl.core._Runtime.singletonExt
//http://blogs.perl.org/users/clinton_gormley/2010/02/forcing-ie-to-accept-script-tags-in-innerhtml.html
//we have to cope with deficiencies between ie and its simulations in this case
var probe = document.createElement("div");
- probe.innerHTML = "<table><div></div></table>";
+ probe.innerHTML = "<table><tbody><tr><td><div></div></td></tr></tbody></table>";
var depth = 0;
while(probe) {
probe = probe.childNodes[0];
@@ -187,23 +189,47 @@ myfaces._impl.core._Runtime.singletonExt
//fortunately a table element also works which is less critical than form elements regarding
//the inner content
- dummyPlaceHolder.innerHTML = "<table>" + markup + "</table>";
+ dummyPlaceHolder.innerHTML = "<table><tbody><tr><td>" + markup + "</td></tr></tbody></table>";
evalNode = dummyPlaceHolder;
for(var cnt = 0; cnt < depth; cnt++) {
evalNode = evalNode.childNodes[0];
}
+ evalNode = (evalNode.parentNode) ? evalNode.parentNode.childNodes : null;
- if('undefined' == typeof evalNode) {
+ if('undefined'==typeof evalNode||null==evalNode) {
//fallback for htmlunit which should be good enough
//to run the tests, maybe we have to wrap it as well
dummyPlaceHolder.innerHTML = "<div>" + markup + "</div>";
//note this is triggered only in htmlunit no other browser
//so we are save here
- evalNode = dummyPlaceHolder.childNodes[0];
+ evalNode = dummyPlaceHolder.childNodes[0].childNodes;
}
parentNode = item.parentNode;
- item.parentNode.replaceChild(evalNode, item);
+
+
+ if('undefined' != typeof evalNode.length) {
+ var oldNode = item;
+ var resultArr = _Lang.objToArray(evalNode);
+
+ for(var cnt = 0; cnt < resultArr.length; cnt++) {
+ if(cnt == 0) {
+ oldNode = parentNode.replaceChild(resultArr[cnt], oldNode);
+ } else {
+ if(oldNode.nextSibling) {
+ oldNode = parentNode.insertBefore(resultArr[cnt], oldNode.nextSibling);
+ } else {
+ oldNode = parentNode.appendChild(resultArr[cnt]);
+
+ }
+ }
+ evalNode = resultArr;
+ }
+
+ } else {
+ evalNode = parentNode.replaceChild(evalNode, item);
+ }
+
//if this as well will fail in the future, we can let ie parse a proper xml
//extract the script elements and then create the script elements manually
@@ -215,7 +241,13 @@ myfaces._impl.core._Runtime.singletonExt
// and remove the old item
//first we have to save the node newly insert for easier access in our eval part
if (myfaces._impl.core._Runtime.isManualScriptEval()) {
- this.runScripts(evalNode);
+ if(evalNode.length) {
+ for(var cnt = 0; cnt < evalNode.length; cnt++) {
+ this.runScripts(evalNode[cnt]);
+ }
+ } else {
+ this.runScripts(evalNode);
+ }
}
return evalNode;
}
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=956408&r1=956407&r2=956408&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 Sun Jun 20 20:27:34 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.xhrCore._AjaxResponse */
myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._AjaxResponse", Object, {
@@ -151,6 +151,7 @@ myfaces._impl.core._Runtime.extendClass(
},
fixViewStates : function() {
+
if (null == this.appliedViewState) {
return;
}
@@ -286,7 +287,7 @@ myfaces._impl.core._Runtime.extendClass(
// 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);
-
+
// 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
// detached or not to prevent manipulation. I'm not sure if that code works in all browser
@@ -294,20 +295,20 @@ myfaces._impl.core._Runtime.extendClass(
// code is safe or if it is worth. If it is not detached, without this code we could update
// the same input hidden view state twice.
//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 searchClosure = function(parentItem) {
- // return parentItem && (parentItem == document);
- //};
- //var sourceFormAncestor = _Dom.getFilteredParent(sourceForm, searchClosure);
- //Is not on the document?
- //if (null == sourceFormAncestor)
- //{
- // Let fixViewStates do the job, because after the blocks are processed, we register
- // the target forms to be updated if any.
- //sourceForm = null;
- //}
+ // 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 searchClosure = function(parentItem) {
+ // return parentItem && (parentItem == document);
+ //};
+ //var sourceFormAncestor = _Dom.getFilteredParent(sourceForm, searchClosure);
+ //Is not on the document?
+ //if (null == sourceFormAncestor)
+ //{
+ // Let fixViewStates do the job, because after the blocks are processed, we register
+ // the target forms to be updated if any.
+ //sourceForm = null;
+ //}
//}
//the source form could be determined absolutely by either the form, the identifier of the node, or the name
@@ -347,15 +348,7 @@ myfaces._impl.core._Runtime.extendClass(
case this.P_VIEWROOT:
var resultNode = this._replaceBody(request, context, cDataBlock);
if (resultNode) {
- var parentForm = _Dom.getParent(resultNode,"form");
- if (null != parentForm)
- {
- this._updateForms.push(parentForm);
- }
- else
- {
- this._updateElems.push(resultNode);
- }
+ this._pushOperationResult(resultNode);
}
break;
case this.P_VIEWHEAD:
@@ -368,30 +361,14 @@ myfaces._impl.core._Runtime.extendClass(
//we assume the cdata block is our body including the tag
var resultNode = this._replaceBody(request, context, cDataBlock);
if (resultNode) {
- var parentForm = _Dom.getParent(resultNode,"form");
- if (null != parentForm)
- {
- this._updateForms.push(parentForm);
- }
- else
- {
- this._updateElems.push(resultNode);
- }
+ this._pushOperationResult(resultNode);
}
break;
default:
var resultNode = this._replaceElement(request, context, node.getAttribute('id'), cDataBlock);
if (resultNode) {
- var parentForm = _Dom.getParent(resultNode,"form");
- if (null != parentForm)
- {
- this._updateForms.push(parentForm);
- }
- else
- {
- this._updateElems.push(resultNode);
- }
+ this._pushOperationResult(resultNode);
}
break;
}
@@ -399,6 +376,30 @@ myfaces._impl.core._Runtime.extendClass(
return true;
},
+ _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");
+ if (null != parentForm)
+ {
+ this._updateForms.push(parentForm);
+ }
+ else
+ {
+ this._updateElems.push(currNode);
+ }
+ });
+ if (resultNode.length) {
+ for (var cnt = 0; cnt < resultNode.length; cnt++) {
+ pushSubnode(resultNode[cnt]);
+ }
+ } else {
+ pushSubnode(resultNode);
+ }
+
+ },
+
/**
* special method to handle the body dom manipulation,
* replacing the entire body does not work fully by simply adding a second body
@@ -540,15 +541,7 @@ myfaces._impl.core._Runtime.extendClass(
nodeHolder, cDataBlock, null);
if (replacementFragment) {
- var parentForm = _Dom.getParent(replacementFragment,"form");
- if (parentForm)
- {
- this._updateForms.push(parentForm);
- }
- else
- {
- this._updateElems.push(replacementFragment);
- }
+ this._pushOperationResult(replacementFragment);
}
} else {
@@ -567,15 +560,7 @@ myfaces._impl.core._Runtime.extendClass(
nodeHolder, cDataBlock, null);
if (replacementFragment) {
- var parentForm = _Dom.getParent(replacementFragment,"form");
- if (null != parentForm)
- {
- this._updateForms.push(parentForm);
- }
- else
- {
- this._updateElems.push(replacementFragment);
- }
+ this._pushOperationResult(replacementFragment);
}
}
@@ -593,13 +578,13 @@ myfaces._impl.core._Runtime.extendClass(
_Impl.MALFORMEDXML, "Error in delete, id not in xml markup");
return false;
}
-
+
var item = _Dom.byId(deleteId);
if (!item) {
throw Error("_AjaxResponse.processDelete Unknown Html-Component-ID: " + deleteId);
}
-
- var parentForm = _Dom.getParent(item,"form");
+
+ var parentForm = _Dom.getParent(item, "form");
if (null != parentForm)
{
this._updateForms.push(parentForm);