myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1622094 - /myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
Date Tue, 02 Sep 2014 19:04:00 GMT
Author: lu4242
Date: Tue Sep  2 19:03:59 2014
New Revision: 1622094

URL: http://svn.apache.org/r1622094
Log:
MYFACES-3918 DefaultFaceletsStateManagementStrategy: keep list of removed client IDs stable
over time

Modified:
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1622094&r1=1622093&r2=1622094&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
(original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
Tue Sep  2 19:03:59 2014
@@ -412,8 +412,13 @@ public class DefaultFaceletsStateManagem
                     String clientId = clientIdsRemoved.get(i);
                     if (!idsRemovedSet.contains(clientId))
                     {
-                        view.invokeOnComponent(context, clientId, new RemoveComponentCallback());
-                        idsRemovedSet.add(clientId);
+                        RemoveComponentCallback callback = new RemoveComponentCallback();
+                        view.invokeOnComponent(context, clientId, callback);
+                        if (callback.isComponentFound())
+                        {
+                            //Add only if component found
+                            idsRemovedSet.add(clientId);
+                        }
                     }
                 }
                 clientIdsRemoved.clear();
@@ -472,32 +477,50 @@ public class DefaultFaceletsStateManagem
 
     public static class RemoveComponentCallback implements ContextCallback
     {
+        private boolean componentFound;
+        
+        public RemoveComponentCallback()
+        {
+            this.componentFound = false;
+        }
+        
         public void invokeContextCallback(FacesContext context,
                 UIComponent target)
         {
-            if (target.getParent() != null)
+            if (target.getParent() != null && 
+                !target.getParent().getChildren().remove(target))
             {
-                if (!target.getParent().getChildren().remove(target))
+                String key = null;
+                if (target.getParent().getFacetCount() > 0)
                 {
-                    String key = null;
-                    if (target.getParent().getFacetCount() > 0)
+                    for (Map.Entry<String, UIComponent> entry :
+                            target.getParent().getFacets().entrySet())
                     {
-                        for (Map.Entry<String, UIComponent> entry :
-                                target.getParent().getFacets().entrySet())
+                        if (entry.getValue()==target)
                         {
-                            if (entry.getValue()==target)
-                            {
-                                key = entry.getKey();
-                                break;
-                            }
+                            key = entry.getKey();
+                            break;
                         }
                     }
-                    if (key != null)
+                }
+                if (key != null)
+                {
+                    UIComponent removedTarget = target.getParent().getFacets().remove(key);
+                    if (removedTarget != null)
                     {
-                        target.getParent().getFacets().remove(key);
+                        this.componentFound = true;
                     }
                 }
             }
+            else
+            {
+                this.componentFound = true;
+            }
+        }
+        
+        public boolean isComponentFound()
+        {
+            return this.componentFound;
         }
     }
 
@@ -1135,9 +1158,25 @@ public class DefaultFaceletsStateManagem
     
     public void suscribeListeners(UIViewRoot uiViewRoot)
     {
-        PostAddPreRemoveFromViewListener componentListener = new PostAddPreRemoveFromViewListener();
-        uiViewRoot.subscribeToViewEvent(PostAddToViewEvent.class, componentListener);
-        uiViewRoot.subscribeToViewEvent(PreRemoveFromViewEvent.class, componentListener);
+        boolean listenerSubscribed = false;
+        List<SystemEventListener> pavList = uiViewRoot.getViewListenersForEventClass(PostAddToViewEvent.class);
+        if (pavList != null)
+        {
+            for (SystemEventListener listener : pavList)
+            {
+                if (listener instanceof PostAddPreRemoveFromViewListener)
+                {
+                    listenerSubscribed = true;
+                    break;
+                }
+            }
+        }
+        if (!listenerSubscribed)
+        {
+            PostAddPreRemoveFromViewListener componentListener = new PostAddPreRemoveFromViewListener();
+            uiViewRoot.subscribeToViewEvent(PostAddToViewEvent.class, componentListener);
+            uiViewRoot.subscribeToViewEvent(PreRemoveFromViewEvent.class, componentListener);
+        }
     }
     
     private void checkIds (FacesContext context, UIComponent component, Set<String>
existingIds)



Mime
View raw message