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 2010/01/31 03:09:47 UTC

svn commit: r904952 - /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Author: lu4242
Date: Sun Jan 31 02:09:47 2010
New Revision: 904952

URL: http://svn.apache.org/viewvc?rev=904952&view=rev
Log:
state map could be empty, prevent save it to reduce state size

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=904952&r1=904951&r2=904952&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Sun Jan 31 02:09:47 2010
@@ -138,7 +138,7 @@
             state = (Object[]) helper.getSerializedViewFromServletSession(context, viewId, serverStateId);
         }
         
-        if (state[1] instanceof Object[])
+        if (state != null && state[1] instanceof Object[])
         {
             Object[] fullState = (Object[]) state[1]; 
             view = (UIViewRoot) internalRestoreTreeStructure((TreeStructComponent)fullState[0]);
@@ -199,86 +199,89 @@
                 throw new FacesException ("unable to create view \"" + viewId + "\"", e);
             }
 
-            states = (Map<String, Object>) state[1];
-            
-            // Visit the children and restore their state.
-            
-            //view.visitTree (VisitContext.createVisitContext (context), new RestoreStateVisitor (states));
-            
-            //Restore state of current components
-            restoreStateFromMap(context, states, view);
-            
-            // 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)
+            if (state != null && state[1] != null)
             {
-                for (String clientId : clientIdsRemoved)
+                states = (Map<String, Object>) state[1];
+                
+                // Visit the children and restore their state.
+                
+                //view.visitTree (VisitContext.createVisitContext (context), new RestoreStateVisitor (states));
+                
+                //Restore state of current components
+                restoreStateFromMap(context, states, view);
+                
+                // 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)
                 {
-                    view.invokeOnComponent(context, clientId, new ContextCallback()
-                        {
-                            public void invokeContextCallback(FacesContext context,
-                                    UIComponent target)
+                    for (String clientId : clientIdsRemoved)
+                    {
+                        view.invokeOnComponent(context, clientId, new ContextCallback()
                             {
-                                if (target.getParent() != null)
+                                public void invokeContextCallback(FacesContext context,
+                                        UIComponent target)
                                 {
-                                    target.getParent().getChildren().remove(target);
+                                    if (target.getParent() != null)
+                                    {
+                                        target.getParent().getChildren().remove(target);
+                                    }
                                 }
-                            }
-                        });
+                            });
+                    }
                 }
-            }
-            
-            List<String> clientIdsAdded = getClientIdsAdded(view);
-            if (clientIdsAdded != null)
-            {
-                for (String clientId : clientIdsAdded)
+                
+                List<String> clientIdsAdded = getClientIdsAdded(view);
+                if (clientIdsAdded != null)
                 {
-                    final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId);
-                    if (wrapper != null)
+                    for (String clientId : clientIdsAdded)
                     {
-                        final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); 
-                        if (addedState != null)
+                        final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId);
+                        if (wrapper != null)
                         {
-                            if (addedState.length == 2)
+                            final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); 
+                            if (addedState != null)
                             {
-                                view = (UIViewRoot) internalRestoreTreeStructure((TreeStructComponent) addedState[0]);
-                                view.processRestoreState(context, addedState[1]);
-                                break;
-                            }
-                            else
-                            {
-                                final String parentClientId = (String) addedState[0];
-                                view.invokeOnComponent(context, parentClientId, new ContextCallback()
+                                if (addedState.length == 2)
+                                {
+                                    view = (UIViewRoot) internalRestoreTreeStructure((TreeStructComponent) addedState[0]);
+                                    view.processRestoreState(context, addedState[1]);
+                                    break;
+                                }
+                                else
                                 {
-                                    public void invokeContextCallback(FacesContext context,
-                                            UIComponent target)
+                                    final String parentClientId = (String) addedState[0];
+                                    view.invokeOnComponent(context, parentClientId, new ContextCallback()
                                     {
-                                        if (addedState[1] != null)
+                                        public void invokeContextCallback(FacesContext context,
+                                                UIComponent target)
                                         {
-                                            String facetName = (String) addedState[1];
-                                            UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]);
-                                            child.processRestoreState(context, addedState[4]);
-                                            target.getFacets().put(facetName,child);
-                                        }
-                                        else
-                                        {
-                                            Integer childIndex = (Integer) addedState[2];
-                                            UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]);
-                                            child.processRestoreState(context, addedState[4]);
-                                            try
+                                            if (addedState[1] != null)
                                             {
-                                                target.getChildren().add(childIndex, child);
+                                                String facetName = (String) addedState[1];
+                                                UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]);
+                                                child.processRestoreState(context, addedState[4]);
+                                                target.getFacets().put(facetName,child);
                                             }
-                                            catch (IndexOutOfBoundsException e)
+                                            else
                                             {
-                                                // We can't be sure about where should be this 
-                                                // item, so just add it. 
-                                                target.getChildren().add(child);
+                                                Integer childIndex = (Integer) addedState[2];
+                                                UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]);
+                                                child.processRestoreState(context, addedState[4]);
+                                                try
+                                                {
+                                                    target.getChildren().add(childIndex, child);
+                                                }
+                                                catch (IndexOutOfBoundsException e)
+                                                {
+                                                    // We can't be sure about where should be this 
+                                                    // item, so just add it. 
+                                                    target.getChildren().add(child);
+                                                }
                                             }
                                         }
-                                    }
-                                });
+                                    });
+                                }
                             }
                         }
                     }
@@ -387,6 +390,11 @@
                 states = new HashMap<String, Object>();
 
                 saveStateOnMap(context,(Map<String,Object>) states, view);
+                
+                if ( ((Map<String,Object>)states).isEmpty())
+                {
+                    states = null;
+                }
             }
             
             // TODO: not sure the best way to handle dynamic adds/removes as mandated by the spec.