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/19 02:18:31 UTC

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

Author: lu4242
Date: Tue Jan 19 01:18:31 2010
New Revision: 900636

URL: http://svn.apache.org/viewvc?rev=900636&view=rev
Log:
MYFACES-2494 Component branches saved with PSS needs to be wrapped

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

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AttachedFullStateWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AttachedFullStateWrapper.java?rev=900636&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AttachedFullStateWrapper.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AttachedFullStateWrapper.java Tue Jan 19 01:18:31 2010
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, 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.
+ */
+package org.apache.myfaces.view.facelets;
+
+import java.io.Serializable;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author: slessard $)
+ * @version $Revision: 701829 $ $Date: 2008-10-05 12:06:02 -0500 (dom, 05 oct 2008) $
+ */
+public class AttachedFullStateWrapper implements Serializable
+{
+    private static final long serialVersionUID = -138360308769803541L;
+    private Object _wrappedStateObject;
+
+    /**
+     * @param clazz
+     *            null means wrappedStateObject is a List of state objects
+     * @param wrappedStateObject
+     */
+    public AttachedFullStateWrapper(Object wrappedStateObject)
+    {
+        if (wrappedStateObject != null && !(wrappedStateObject instanceof Serializable))
+        {
+            throw new IllegalArgumentException("Attached state for Object for Component State"
+                    + wrappedStateObject.getClass().getName() + ") is not serializable");
+        }
+        _wrappedStateObject = wrappedStateObject;
+    }
+
+    public Object getWrappedStateObject()
+    {
+        return _wrappedStateObject;
+    }
+}

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=900636&r1=900635&r2=900636&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 Tue Jan 19 01:18:31 2010
@@ -207,8 +207,9 @@
         {
             for (String clientId : clientIdsAdded)
             {
-                final Object[] addedState = (Object[]) states.get(clientId); 
-                if (addedState != null && addedState.length == 5)
+                final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId);
+                final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); 
+                if (addedState != null)
                 {
                     final String parentClientId = (String) addedState[0];
                     view.invokeOnComponent(context, parentClientId, new ContextCallback()
@@ -381,7 +382,19 @@
             Object state = states.get(component.getClientId());
             if (state != null)
             {
-                component.restoreState(context, state);
+                if (state instanceof AttachedFullStateWrapper)
+                {
+                    //Don't restore this one! It will be restored when the algorithm remove and add it.
+                    return;
+                }
+                try
+                {
+                    component.restoreState(context, state);
+                }
+                catch(Exception e)
+                {
+                    throw new IllegalStateException("Error restoring component: "+component.getClientId(), e);
+                }
             }
     
             //Scan children
@@ -474,13 +487,13 @@
                         {
                             //Save all required info to restore the subtree.
                             //This includes position, structure and state of subtree
-                            states.put(child.getClientId(), 
+                            states.put(child.getClientId(), new AttachedFullStateWrapper( 
                                     new Object[]{
                                         currentClientId,
                                         null,
                                         pos,
                                         internalBuildTreeStructureToSave(child),
-                                        child.processSaveState(context)});
+                                        child.processSaveState(context)}));
                         }
                         else
                         {
@@ -507,12 +520,12 @@
                         {
                             //Save all required info to restore the subtree.
                             //This includes position, structure and state of subtree
-                            states.put(child.getClientId(), new Object[]{
+                            states.put(child.getClientId(),new AttachedFullStateWrapper(new Object[]{
                                 currentClientId,
                                 facetName,
                                 null,
                                 internalBuildTreeStructureToSave(child),
-                                child.processSaveState(context)});
+                                child.processSaveState(context)}));
                         }
                         else
                         {
@@ -670,6 +683,9 @@
                 setClientsIdsAdded(uiViewRoot, clientIdsAdded);
                 
                 component.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW, Boolean.TRUE);
+
+                //Reset initial state, so it can be saved fully later
+                component.clearInitialState();
             }
             else
             {