You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/12/08 02:46:56 UTC

svn commit: r1418590 - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Author: lu4242
Date: Sat Dec  8 01:46:56 2012
New Revision: 1418590

URL: http://svn.apache.org/viewvc?rev=1418590&view=rev
Log:
small refactor, more some inner classes out of restoreState method.

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

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1418590&r1=1418589&r2=1418590&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Sat Dec  8 01:46:56 2012
@@ -339,72 +339,7 @@ public class DefaultFaceletsStateManagem
                 {
                     view.getAttributes().put(ComponentSupport.FACELET_STATE_INSTANCE,  faceletViewState);
                 }
-                
-                // TODO: handle dynamic add/removes as mandated by the spec.  Not sure how to do handle this yet.
-                List<String> clientIdsRemoved = getClientIdsRemoved(view);
-                
-                if (clientIdsRemoved != null)
-                {
-                    Set<String> idsRemovedSet = new HashSet<String>(HashMapUtils.calcCapacity(clientIdsRemoved.size()));
-                    context.getAttributes().put(FaceletViewDeclarationLanguage.REMOVING_COMPONENTS_BUILD, Boolean.TRUE);
-                    try
-                    {
-                        // perf: clientIds are ArrayList: see method registerOnAddRemoveList(String)
-                        for (int i = 0, size = clientIdsRemoved.size(); i < size; i++)
-                        {
-                            String clientId = clientIdsRemoved.get(i);
-                            if (!idsRemovedSet.contains(clientId))
-                            {
-                                view.invokeOnComponent(context, clientId, new RemoveComponentCallback());
-                                idsRemovedSet.add(clientId);
-                            }
-                        }
-                        clientIdsRemoved.clear();
-                        clientIdsRemoved.addAll(idsRemovedSet);
-                    }
-                    finally
-                    {
-                        context.getAttributes().remove(FaceletViewDeclarationLanguage.REMOVING_COMPONENTS_BUILD);
-                    }
-                }
-                List<String> clientIdsAdded = getClientIdsAdded(view);
-                if (clientIdsAdded != null)
-                {
-                    Set<String> idsAddedSet = new HashSet<String>(HashMapUtils.calcCapacity(clientIdsAdded.size()));
-                    // perf: clientIds are ArrayList: see method setClientsIdsAdded(String)
-                    for (int i = 0, size = clientIdsAdded.size(); i < size; i++)
-                    {
-                        String clientId = clientIdsAdded.get(i);
-                        if (!idsAddedSet.contains(clientId))
-                        {
-                            final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId);
-                            if (wrapper != null)
-                            {
-                                final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); 
-                                if (addedState != null)
-                                {
-                                    if (addedState.length == 2)
-                                    {
-                                        view = (UIViewRoot)
-                                                internalRestoreTreeStructure((TreeStructComponent) addedState[0]);
-                                        view.processRestoreState(context, addedState[1]);
-                                        break;
-                                    }
-                                    else
-                                    {
-                                        final String parentClientId = (String) addedState[0];
-                                        view.invokeOnComponent(context, parentClientId, 
-                                            new AddComponentCallback(addedState));
-                                    }
-                                }
-                            }
-                            idsAddedSet.add(clientId);
-                        }
-                    }
-                    // Reset this list, because it will be calculated later when the view is being saved
-                    // in the right order, preventing duplicates (see COMPONENT_ADDED_AFTER_BUILD_VIEW for details).
-                    clientIdsAdded.clear();
-                }
+                handleDynamicAddedRemovedComponents(context, view, states);
             }
         }
         // Restore binding, because UIViewRoot.processRestoreState() is never called
@@ -428,6 +363,74 @@ public class DefaultFaceletsStateManagem
         //}
         return view;
     }
+    
+    public void handleDynamicAddedRemovedComponents(FacesContext context, UIViewRoot view, Map<String, Object> states)
+    {
+        List<String> clientIdsRemoved = getClientIdsRemoved(view);
+
+        if (clientIdsRemoved != null)
+        {
+            Set<String> idsRemovedSet = new HashSet<String>(HashMapUtils.calcCapacity(clientIdsRemoved.size()));
+            context.getAttributes().put(FaceletViewDeclarationLanguage.REMOVING_COMPONENTS_BUILD, Boolean.TRUE);
+            try
+            {
+                // perf: clientIds are ArrayList: see method registerOnAddRemoveList(String)
+                for (int i = 0, size = clientIdsRemoved.size(); i < size; i++)
+                {
+                    String clientId = clientIdsRemoved.get(i);
+                    if (!idsRemovedSet.contains(clientId))
+                    {
+                        view.invokeOnComponent(context, clientId, new RemoveComponentCallback());
+                        idsRemovedSet.add(clientId);
+                    }
+                }
+                clientIdsRemoved.clear();
+                clientIdsRemoved.addAll(idsRemovedSet);
+            }
+            finally
+            {
+                context.getAttributes().remove(FaceletViewDeclarationLanguage.REMOVING_COMPONENTS_BUILD);
+            }
+        }
+        List<String> clientIdsAdded = getClientIdsAdded(view);
+        if (clientIdsAdded != null)
+        {
+            Set<String> idsAddedSet = new HashSet<String>(HashMapUtils.calcCapacity(clientIdsAdded.size()));
+            // perf: clientIds are ArrayList: see method setClientsIdsAdded(String)
+            for (int i = 0, size = clientIdsAdded.size(); i < size; i++)
+            {
+                String clientId = clientIdsAdded.get(i);
+                if (!idsAddedSet.contains(clientId))
+                {
+                    final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId);
+                    if (wrapper != null)
+                    {
+                        final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); 
+                        if (addedState != null)
+                        {
+                            if (addedState.length == 2)
+                            {
+                                view = (UIViewRoot)
+                                        internalRestoreTreeStructure((TreeStructComponent) addedState[0]);
+                                view.processRestoreState(context, addedState[1]);
+                                break;
+                            }
+                            else
+                            {
+                                final String parentClientId = (String) addedState[0];
+                                view.invokeOnComponent(context, parentClientId, 
+                                    new AddComponentCallback(addedState));
+                            }
+                        }
+                    }
+                    idsAddedSet.add(clientId);
+                }
+            }
+            // Reset this list, because it will be calculated later when the view is being saved
+            // in the right order, preventing duplicates (see COMPONENT_ADDED_AFTER_BUILD_VIEW for details).
+            clientIdsAdded.clear();
+        }
+    }
 
     public static class RemoveComponentCallback implements ContextCallback
     {