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 2011/04/28 21:45:26 UTC

svn commit: r1097585 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/_Dom.js _util/_Lang.js core/Impl.js xhrCore/_AjaxResponse.js xhrCore/_Transports.js

Author: werpu
Date: Thu Apr 28 19:45:26 2011
New Revision: 1097585

URL: http://svn.apache.org/viewvc?rev=1097585&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-3118



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/core/Impl.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/_Transports.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=1097585&r1=1097584&r2=1097585&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 Thu Apr 28 19:45:26 2011
@@ -161,16 +161,56 @@ myfaces._impl.core._Runtime.singletonExt
         }
     },
 
+
+    /**
+     * determines to fetch a node
+     * from its id or name, the name case
+     * only works if the element is unique in its name
+     * @param elem
+     */
+    byIdOrName: function(elem) {
+        if(!this._Lang.isString(elem)) return elem;
+        if(!elem) return null;
+        var ret = this.byId(elem);
+        if(ret) return ret;
+        //we try the unique name fallback
+        var items = document.getElementsByName(elem);
+        return ((items.length == 1)? items[0]: null);
+    },
+
+    /**
+     * node id or name, determines the valid form identifier of a node
+     * depending on its uniqueness
+     *
+     * Usually the id is chosen for an elem, but if the id does not
+     * exist we try a name fallback. If the passed element has a unique
+     * name we can use that one as subsequent identifier.
+     *
+     *
+     * @param {String} elem
+     */
     nodeIdOrName: function(elem) {
         if (elem) {
+            //just to make sure that the pas
+            var origElemIdentifier = elem;
             elem = this.byId(elem);
+            if(!elem) return null;
             //detached element handling, we also store the element name
             //to get a fallback option in case the identifier is not determinable
             // anymore, in case of a framework induced detachment the element.name should
             // be shared if the identifier is not determinable anymore
+            //the downside of this method is the element name must be unique
+            //which in case of jsf it is
             var elementId = elem.id || elem.name;
-            if ((elementId == null || elementId == '') && elem.name) {
+            if ((elem.id == null || elem.id == '') && elem.name) {
                 elementId = elem.name;
+
+                //last check for uniqueness
+                if(this.getElementsByName(elementId).length > 1) {
+                    //no unique element name so we need to perform
+                    //a return null to let the caller deal with this issue
+                    return null;
+                }
             }
             return elementId;
         }
@@ -643,6 +683,8 @@ myfaces._impl.core._Runtime.singletonExt
      * @param deepScan if set to true a deep scan is performed otherwise a shallow scan
      */
     findByTagNames: function(fragment, tagNames, deepScan) {
+        var nodeType = fragment.nodeType;
+        if(nodeType != 1 && nodeType != 9 && nodeType != 11) return null;
 
 
         //shortcut for single components
@@ -695,6 +737,9 @@ myfaces._impl.core._Runtime.singletonExt
      *
      */
     findByTagName : function(fragment, tagName, deepScan) {
+        var nodeType = fragment.nodeType;
+        if(nodeType != 1 && nodeType != 9 && nodeType != 11) return null;
+
 
         //remapping to save a few bytes
         var _Lang = this._Lang;
@@ -731,6 +776,9 @@ myfaces._impl.core._Runtime.singletonExt
     ,
 
     findByName : function(fragment, name, deepScan) {
+        var nodeType = fragment.nodeType;
+        if(nodeType != 1 && nodeType != 9 && nodeType != 11) return null;
+
         var _Lang = this._Lang;
         var filter = function(node) {
             return  node.name && _Lang.equalsIgnoreCase(node.name, name);
@@ -743,7 +791,6 @@ myfaces._impl.core._Runtime.singletonExt
                 var ret = _Lang.objToArray(fragment.getElementsByName(name));
                 if (fragment.name == name) ret.unshift(fragment);
                 return ret;
-
             }
 
             if (deepScan && _Lang.exists(fragment, "querySelectorAll")) {

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=1097585&r1=1097584&r2=1097585&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 Thu Apr 28 19:45:26 2011
@@ -549,12 +549,14 @@ myfaces._impl.core._Runtime.singletonDel
      * @param scope (optional) the scope to apply the closure to
      */
     arrForEach: function(arr, func /*startPos, scope*/) {
+        if(!arr || !arr.length ) return;
         try {
             var startPos = Number(arguments[2]) || 0;
             var thisObj = arguments[3];
 
             //check for an existing foreach mapping on array prototypes
-            if (Array.prototype.forEach) {
+            //IE9 still does not pass array objects as result for dom ops
+            if (Array.prototype.forEach && arr.forEach) {
                 (startPos) ? arr.slice(startPos).forEach(func, thisObj) : arr.forEach(func, thisObj);
             } else {
                 startPos = (startPos < 0) ? Math.ceil(startPos) : Math.floor(startPos);
@@ -589,6 +591,7 @@ myfaces._impl.core._Runtime.singletonDel
      *
      */
     arrFilter: function(arr, func /*startPos, scope*/) {
+        if(!arr || !arr.length ) return [];
         try {
             var startPos = Number(arguments[2]) || 0;
             var thisObj = arguments[3];
@@ -629,7 +632,7 @@ myfaces._impl.core._Runtime.singletonDel
      * @param element the index to search for
      */
     arrIndexOf: function(arr, element /*fromIndex*/) {
-        if (!arr) return -1;
+        if (!arr || !arr.length) return -1;
         var pos = Number(arguments[2]) || 0;
 
         if (Array.prototype.indexOf) {

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js?rev=1097585&r1=1097584&r2=1097585&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js Thu Apr 28 19:45:26 2011
@@ -157,7 +157,7 @@ myfaces._impl.core._Runtime.singletonExt
             event = window.event || null;
         }
 
-        elem = _Lang.byId(elem);
+        elem = _Dom.byIdOrName(elem);
         var elementId = _Dom.nodeIdOrName(elem);
 
         /*

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=1097585&r1=1097584&r2=1097585&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 Thu Apr 28 19:45:26 2011
@@ -204,7 +204,7 @@ myfaces._impl.core._Runtime.extendClass(
     },
 
     _setVSTInnerForms: function(elem) {
-        elem = this._Lang.byId(elem);
+        elem = this._Dom.byIdOrName(elem);
         var replacedForms = this._Dom.findByTagName(elem, "form", false);
         var applyVST = this._Lang.hitch(this, function(elem) {
             this._setVSTForm(elem);
@@ -539,9 +539,14 @@ myfaces._impl.core._Runtime.extendClass(
      */
     replaceHtmlItem : function(request, context, itemIdToReplace, markup) {
         try {
-            // (itemIdToReplace instanceof Node) is NOT compatible with IE8
+            //TODO make a detachement fixup which tries to replace the item
+            //with the correct name upon its parent form if given
+
+
+            var origIdentifier = itemIdToReplace;
             var item = (!this._Lang.isString(itemIdToReplace)) ? itemIdToReplace :
-                    this._Dom.byId(itemIdToReplace) /*used to call getElementFromForm*/;
+                    this._Dom.byIdOrName(itemIdToReplace);
+
             if (!item) {
                 throw Error(this._Lang.getMessage("ERR_ITEM_ID_NOTFOUND", null,"_AjaxResponse.replaceHtmlItem",(itemIdToReplace)? itemIdToReplace.toString():"undefined"));
             }
@@ -595,7 +600,7 @@ myfaces._impl.core._Runtime.extendClass(
         var replacementFragment;
         if (isBefore) {
             beforeId = this._Lang.trim(beforeId);
-            var beforeNode = document.getElementById(beforeId);
+            var beforeNode = this._Dom.byIdOrName(beforeId);
             if (!beforeNode) {
                 _Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML,this._Lang.getMessage("ERR_PPR_INSERTBEFID_1", null,"_AjaxResponse.processInsert",beforeId));
                 return false;
@@ -617,7 +622,7 @@ myfaces._impl.core._Runtime.extendClass(
 
         } else {
             afterId = this._Lang.trim(afterId);
-            var afterNode = document.getElementById(afterId);
+            var afterNode = this._Dom.byIdOrName(afterId);
             if (!afterNode) {
                 _Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML, this._Lang.getMessage("ERR_PPR_INSERTBEFID_2", null,"_AjaxResponse.processInsert", afterId));
                 return false;
@@ -652,7 +657,7 @@ myfaces._impl.core._Runtime.extendClass(
             return false;
         }
 
-        var item = this._Dom.byId(deleteId);
+        var item = this._Dom.byIdOrName(deleteId);
         if (!item) {
             throw Error(this._Lang.getMessage("ERR_PPR_UNKNOWNCID", null,"_AjaxResponse.processDelete",deleteId));
         }

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js?rev=1097585&r1=1097584&r2=1097585&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js Thu Apr 28 19:45:26 2011
@@ -226,6 +226,16 @@ myfaces._impl.core._Runtime.extendClass(
      */
     response : function(request, context) {
         var internalContext = context._mfInternal;
+
+        //the normal usecase is that the request knows about its response
+        //which normally is temporary stored within the _mfRequest object
+        //(aka call from a finished request)
+        //if no _mfRequest object is given which means an external call we
+        //have a call from the outside
+
+        //TODO check if we cannot eliminate the _mfRequest object in the long run
+        //given we have to pass a request object anyway
+
         var ajaxObj = (internalContext && internalContext._mfRequest) ||  new (this._getAjaxReqClass(context))({xhr: request, context: context});
         //ie gc fix
         if(internalContext && internalContext._mfRequest){