myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1004094 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/view/facelets/ test/java/org/apache/myfaces/view/facelets/
Date Mon, 04 Oct 2010 03:23:16 GMT
Author: lu4242
Date: Mon Oct  4 03:23:16 2010
New Revision: 1004094

URL: http://svn.apache.org/viewvc?rev=1004094&view=rev
Log:
MYFACES-2935 SystemEvent Acid Test (fix test stable, added ids must be added in the same order
the tree is traversed to restore properly )

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategyTest.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=1004094&r1=1004093&r2=1004094&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
Mon Oct  4 03:23:16 2010
@@ -81,6 +81,10 @@ import org.apache.myfaces.shared_impl.ut
  *    all its children and facets from view inclusive.
  * 9. It is necessary to save and restore the list of added/removed components between several
  *    requests.
+ * 10.All components ids removed in any moment of time must be preserved.
+ * 11.Each component must be restored only once.
+ * 11.The order is important for ids added when it is traversed the tree, otherwise the algorithm

+ *    could change the order in which components will be restored.  
  * 
  * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
  * @version $Revision: 793245 $ $Date: 2009-07-11 18:50:53 -0500 (Sat, 11 Jul 2009) $
@@ -99,10 +103,13 @@ public class DefaultFaceletsStateManagem
      * state saving. There are two possible values:
      * 
      * Key not present: The component uses pss.
-     * Boolean.TRUE: The component was added to the view after build view.
-     * Boolean.FALSE: The component was removed/added to the view. Itself and all
+     * ComponentState.ADD: The component was added to the view after build view.
+     * ComponentState.REMOVE_ADD: The component was removed/added to the view. Itself and
all
      * descendants should be saved and restored, but we have to unregister/register
-     * from CLIENTIDS_ADDED and CLIENTIDS_REMOVED lists.
+     * from CLIENTIDS_ADDED and CLIENTIDS_REMOVED lists. See ComponentSupport.markComponentToRestoreFully
+     * for details.
+     * ComponentState.ADDED: The component has been added or removed/added, but it has
+     * been already processed.
      */
     public  static final String COMPONENT_ADDED_AFTER_BUILD_VIEW = "oam.COMPONENT_ADDED_AFTER_BUILD_VIEW";

     
@@ -227,41 +234,49 @@ public class DefaultFaceletsStateManagem
                 if (clientIdsRemoved != null)
                 {
                     Set<String> idsRemovedSet = new HashSet<String>(HashMapUtils.calcCapacity(clientIdsRemoved.size()));
-                    for (String clientId : clientIdsRemoved)
+                    context.getAttributes().put(FaceletViewDeclarationLanguage.REMOVING_COMPONENTS_BUILD,
Boolean.TRUE);
+                    try
                     {
-                        if (!idsRemovedSet.contains(clientId))
+                        for (String clientId : clientIdsRemoved)
                         {
-                            view.invokeOnComponent(context, clientId, new ContextCallback()
-                                {
-                                    public void invokeContextCallback(FacesContext context,
-                                            UIComponent target)
+                            if (!idsRemovedSet.contains(clientId))
+                            {
+                                view.invokeOnComponent(context, clientId, new ContextCallback()
                                     {
-                                        if (target.getParent() != null)
+                                        public void invokeContextCallback(FacesContext context,
+                                                UIComponent target)
                                         {
-                                            if (!target.getParent().getChildren().remove(target))
+                                            if (target.getParent() != null)
                                             {
-                                                String key = null;
-                                                for (Map.Entry<String, UIComponent>
entry : target.getParent().getFacets().entrySet())
+                                                if (!target.getParent().getChildren().remove(target))
                                                 {
-                                                    if (entry.getValue()==target)
+                                                    String key = null;
+                                                    for (Map.Entry<String, UIComponent>
entry : target.getParent().getFacets().entrySet())
                                                     {
-                                                        key = entry.getKey();
-                                                        break;
+                                                        if (entry.getValue()==target)
+                                                        {
+                                                            key = entry.getKey();
+                                                            break;
+                                                        }
+                                                    }
+                                                    if (key != null)
+                                                    {
+                                                        target.getParent().getFacets().remove(key);
                                                     }
-                                                }
-                                                if (key != null)
-                                                {
-                                                    target.getParent().getFacets().remove(key);
                                                 }
                                             }
                                         }
-                                    }
-                                });
-                            idsRemovedSet.add(clientId);
+                                    });
+                                idsRemovedSet.add(clientId);
+                            }
                         }
+                        clientIdsRemoved.clear();
+                        clientIdsRemoved.addAll(idsRemovedSet);
+                    }
+                    finally
+                    {
+                        context.getAttributes().remove(FaceletViewDeclarationLanguage.REMOVING_COMPONENTS_BUILD);
                     }
-                    clientIdsRemoved.clear();
-                    clientIdsRemoved.addAll(idsRemovedSet);
                 }
                 
                 List<String> clientIdsAdded = getClientIdsAdded(view);
@@ -323,8 +338,9 @@ public class DefaultFaceletsStateManagem
                             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();
-                    clientIdsAdded.addAll(idsAddedSet);
                 }
             }
         }
@@ -637,6 +653,10 @@ public class DefaultFaceletsStateManagem
                                 registerOnAddList(child.getClientId());
                                 child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.ADDED);
                             }
+                            else if (ComponentState.ADDED.equals(componentAddedAfterBuildView))
+                            {
+                                registerOnAddList(child.getClientId());
+                            }
                             ensureClearInitialState(child);
                             //Save all required info to restore the subtree.
                             //This includes position, structure and state of subtree
@@ -681,6 +701,10 @@ public class DefaultFaceletsStateManagem
                                 registerOnAddList(child.getClientId());
                                 child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.ADDED);
                             }
+                            else if (ComponentState.ADDED.equals(componentAddedAfterBuildView))
+                            {
+                                registerOnAddList(child.getClientId());
+                            }
                             //Save all required info to restore the subtree.
                             //This includes position, structure and state of subtree
                             ensureClearInitialState(child);
@@ -879,6 +903,15 @@ public class DefaultFaceletsStateManagem
             }
             else
             {
+                // In this case if we are removing components on build, it is not necessary
to register
+                // again the current id, and its more, it could cause a concurrent exception.
But note
+                // we need to propagate PreRemoveFromViewEvent, otherwise the view will not
be restored
+                // correctly.
+                if (FaceletViewDeclarationLanguage.isRemovingComponentBuild(facesContext))
+                {
+                    return;
+                }
+                
                 //PreRemoveFromViewEvent
                 UIViewRoot uiViewRoot = facesContext.getViewRoot();
                 

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=1004094&r1=1004093&r2=1004094&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
Mon Oct  4 03:23:16 2010
@@ -220,6 +220,8 @@ public class FaceletViewDeclarationLangu
     public final static String REFRESH_TRANSIENT_BUILD_ON_PSS = "org.apache.myfaces.REFRESH_TRANSIENT_BUILD_ON_PSS";
     
     public final static String USING_PSS_ON_THIS_VIEW = "org.apache.myfaces.USING_PSS_ON_THIS_VIEW";
+    
+    public final static String REMOVING_COMPONENTS_BUILD = "org.apache.myfaces.REMOVING_COMPONENTS_BUILD";
     //END CONSTANTS SET ON BUILD VIEW
     
     /**
@@ -587,7 +589,12 @@ public class FaceletViewDeclarationLangu
     {
         return context.getAttributes().containsKey(REFRESHING_TRANSIENT_BUILD);
     }
-    
+
+    public static boolean isRemovingComponentBuild(FacesContext context)
+    {
+        return context.getAttributes().containsKey(REMOVING_COMPONENTS_BUILD);
+    }
+
     public static boolean isMarkInitialState(FacesContext context)
     {
         return context.getAttributes().containsKey(MARK_INITIAL_STATE_KEY);

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategyTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategyTest.java?rev=1004094&r1=1004093&r2=1004094&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategyTest.java
(original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategyTest.java
Mon Oct  4 03:23:16 2010
@@ -22,7 +22,6 @@ import java.beans.BeanInfo;
 import java.io.IOException;
 import java.util.Iterator;
 
-import javax.faces.FacesException;
 import javax.faces.FactoryFinder;
 import javax.faces.application.Resource;
 import javax.faces.component.UIComponent;
@@ -33,6 +32,7 @@ import javax.faces.component.html.HtmlFo
 import javax.faces.component.html.HtmlInputText;
 import javax.faces.component.html.HtmlOutputText;
 import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
 import javax.faces.event.PostAddToViewEvent;
 import javax.faces.render.RenderKitFactory;
 import javax.faces.render.ResponseStateManager;
@@ -41,27 +41,32 @@ import javax.faces.view.ViewDeclarationL
 import javax.faces.view.ViewDeclarationLanguageFactory;
 import javax.faces.view.ViewMetadata;
 
+import org.apache.myfaces.application.ApplicationFactoryImpl;
 import org.apache.myfaces.component.visit.VisitContextFactoryImpl;
 import org.apache.myfaces.renderkit.html.HtmlButtonRenderer;
 import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
 import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
-import org.apache.myfaces.view.ViewMetadataBase;
-import org.apache.myfaces.test.base.AbstractJsfTestCase;
+import org.apache.myfaces.test.base.junit4.AbstractJsfConfigurableMockTestCase;
 import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.view.ViewMetadataBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.inject.cglib.proxy.Factory;
 
 public class DefaultFaceletsStateManagementStrategyTest extends
-        AbstractJsfTestCase
+        AbstractJsfConfigurableMockTestCase
 {
 
-    public DefaultFaceletsStateManagementStrategyTest(String name)
+    public DefaultFaceletsStateManagementStrategyTest()
     {
-        super(name);
+        super();
     }
     
     public Object stateToRestore;
     
     @Override
-    protected void setUp() throws Exception
+    public void setUp() throws Exception
     {
         super.setUp();
         
@@ -106,10 +111,8 @@ public class DefaultFaceletsStateManagem
                 new HtmlTextRenderer());           
     }
 
-
-    
     @Override
-    protected void tearDown() throws Exception
+    public void tearDown() throws Exception
     {
         stateToRestore = null;
         super.tearDown();
@@ -128,9 +131,18 @@ public class DefaultFaceletsStateManagem
         
     }
     
-    public void testSimpleSaveRestore() throws Exception
+    @Override
+    protected void setFactories() throws Exception
     {
+        super.setFactories();
+        FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+                ApplicationFactoryImpl.class.getName());
         FactoryFinder.setFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY, MockViewDeclarationLanguageFactory.class.getName());
+    }
+
+    @Test
+    public void testSimpleSaveRestore() throws Exception
+    {
         ViewDeclarationLanguage vdl =((MockViewDeclarationLanguageFactory)FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY)).vdl;
         DefaultFaceletsStateManagementStrategy stateManagement = new DefaultFaceletsStateManagementStrategy();
         
@@ -138,21 +150,27 @@ public class DefaultFaceletsStateManagem
         
         UIViewRoot viewRoot = vdl.createView(facesContext, "/root");
         vdl.buildView(facesContext, viewRoot);
+        stateManagement.suscribeListeners(viewRoot);
         
         viewRoot.getAttributes().put("somekey", "somevalue");
         
         Object state1 = stateManagement.saveView(facesContext);
         stateToRestore = state1;
+        facesContext.setViewRoot(null);
         stateManagement.restoreView(facesContext, "/root", viewRoot.getRenderKitId());
         
         viewRoot = facesContext.getViewRoot();
         
-        assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertNotNull(viewRoot.findComponent("form1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:foo1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:var1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:button1"));
     }
     
+    @Test
     public void testSaveRestoreAddComponent() throws Exception
     {
-        FactoryFinder.setFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY, MockViewDeclarationLanguageFactory.class.getName());
         ViewDeclarationLanguage vdl =((MockViewDeclarationLanguageFactory)FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY)).vdl;
         DefaultFaceletsStateManagementStrategy stateManagement = new DefaultFaceletsStateManagementStrategy();
         
@@ -160,7 +178,8 @@ public class DefaultFaceletsStateManagem
         
         UIViewRoot viewRoot = vdl.createView(facesContext, "/root");
         vdl.buildView(facesContext, viewRoot);
-        
+        stateManagement.suscribeListeners(viewRoot);
+
         viewRoot.getAttributes().put("somekey", "somevalue");
         
         HtmlOutputText a = new HtmlOutputText();
@@ -170,27 +189,247 @@ public class DefaultFaceletsStateManagem
         
         viewRoot.getChildren().add(a);
         
-        //Simulate event
-        PostAddToViewEvent evt = new PostAddToViewEvent(a);
-        
-        DefaultFaceletsStateManagementStrategy.PostAddPreRemoveFromViewListener listener
=
-            new DefaultFaceletsStateManagementStrategy.PostAddPreRemoveFromViewListener();
-        
-        listener.processEvent(evt);
-        
         Object state1 = stateManagement.saveView(facesContext);
         stateToRestore = state1;
+        facesContext.setViewRoot(null);
         stateManagement.restoreView(facesContext, "/root", viewRoot.getRenderKitId());
         
         viewRoot = facesContext.getViewRoot();
         
-        assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertNotNull(viewRoot.findComponent("form1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:foo1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:var1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:button1"));
+        
+        a = (HtmlOutputText) viewRoot.findComponent("output1");
+        Assert.assertNotNull(a);
+        Assert.assertEquals("testOutput1",a.getValue());
+    }
+    
+    @Test
+    public void testSaveRestoreAddComponentMultiplePostback() throws Exception
+    {
+        ViewDeclarationLanguage vdl =((MockViewDeclarationLanguageFactory)FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY)).vdl;
+        DefaultFaceletsStateManagementStrategy stateManagement = new DefaultFaceletsStateManagementStrategy();
+        
+        servletContext.addInitParameter("javax.faces.STATE_SAVING_METHOD", "client");
+        
+        UIViewRoot viewRoot = vdl.createView(facesContext, "/root");
+        
+        facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
+        
+        vdl.buildView(facesContext, viewRoot);
+        
+        stateManagement.suscribeListeners(viewRoot);
+        
+        facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
+        
+        viewRoot.getAttributes().put("somekey", "somevalue");
+        
+        HtmlOutputText a = new HtmlOutputText();
+        a.setId("output1");
+        a.setValue("testOutput1");
+        viewRoot.getChildren().add(a);
+        
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        HtmlOutputText b = new HtmlOutputText();
+        b.setId("output2");
+        b.setValue("testOutput2");
+        viewRoot.getChildren().add(b);
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+        
+        HtmlOutputText c = new HtmlOutputText();
+        c.setId("output3");
+        c.setValue("testOutput3");
+        viewRoot.getChildren().add(c);
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+        
+        HtmlOutputText d = new HtmlOutputText();
+        d.setId("output4");
+        d.setValue("testOutput4");
+        viewRoot.getChildren().add(d);
+        
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+        
+        Assert.assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertNotNull(viewRoot.findComponent("form1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:foo1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:var1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:button1"));
+        
+        a = (HtmlOutputText) viewRoot.findComponent("output1");
+        Assert.assertNotNull(a);
+        Assert.assertEquals("testOutput1",a.getValue());
+        b = (HtmlOutputText) viewRoot.findComponent("output2");
+        Assert.assertNotNull(b);
+        Assert.assertEquals("testOutput2",b.getValue());
+        c = (HtmlOutputText) viewRoot.findComponent("output3");
+        Assert.assertNotNull(c);
+        Assert.assertEquals("testOutput3",c.getValue());
+        d = (HtmlOutputText) viewRoot.findComponent("output4");
+        Assert.assertNotNull(d);
+        Assert.assertEquals("testOutput4",d.getValue());
+    }
+    
+    @Test
+    public void testSaveRestoreToogleComponent() throws Exception
+    {
+        ViewDeclarationLanguage vdl =((MockViewDeclarationLanguageFactory)FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY)).vdl;
+        DefaultFaceletsStateManagementStrategy stateManagement = new DefaultFaceletsStateManagementStrategy();
+        
+        servletContext.addInitParameter("javax.faces.STATE_SAVING_METHOD", "client");
+        
+        UIViewRoot viewRoot = vdl.createView(facesContext, "/root");
+        vdl.buildView(facesContext, viewRoot);
+        stateManagement.suscribeListeners(viewRoot);
+
+        viewRoot.getAttributes().put("somekey", "somevalue");
+        
+        HtmlOutputText a = new HtmlOutputText();
+        a.setId("output1");
+        a.setValue("testOutput1");
+        
+        viewRoot.getChildren().add(a);
+        
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+        
+        Assert.assertEquals("form1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output1",viewRoot.getChildren().get(1).getId());
+        
+        UIComponent component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("output1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("form1",viewRoot.getChildren().get(1).getId());
+        
+        component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("form1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output1",viewRoot.getChildren().get(1).getId());
+        
+        component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("output1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("form1",viewRoot.getChildren().get(1).getId());
+        
+        component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("form1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output1",viewRoot.getChildren().get(1).getId());
+        
+        Assert.assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertNotNull(viewRoot.findComponent("form1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:foo1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:var1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:button1"));
+        
+        a = (HtmlOutputText) viewRoot.findComponent("output1");
+        Assert.assertNotNull(a);
+        Assert.assertEquals("testOutput1",a.getValue());
+    }
+    
+    @Test
+    public void testSaveRestoreToogleComponent2() throws Exception
+    {
+        ViewDeclarationLanguage vdl =((MockViewDeclarationLanguageFactory)FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY)).vdl;
+        DefaultFaceletsStateManagementStrategy stateManagement = new DefaultFaceletsStateManagementStrategy();
+        
+        servletContext.addInitParameter("javax.faces.STATE_SAVING_METHOD", "client");
+        
+        UIViewRoot viewRoot = vdl.createView(facesContext, "/root");
+        vdl.buildView(facesContext, viewRoot);
+        stateManagement.suscribeListeners(viewRoot);
+
+        viewRoot.getAttributes().put("somekey", "somevalue");
+        
+        HtmlOutputText a = new HtmlOutputText();
+        a.setId("output1");
+        a.setValue("testOutput1");        
+        viewRoot.getChildren().add(a);
+
+        HtmlOutputText b = new HtmlOutputText();
+        b.setId("output2");
+        b.setValue("testOutput2");        
+        viewRoot.getChildren().add(b);
+        
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+        
+        Assert.assertEquals("form1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output1",viewRoot.getChildren().get(1).getId());
+        Assert.assertEquals("output2",viewRoot.getChildren().get(2).getId());
+        
+        UIComponent component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("output1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output2",viewRoot.getChildren().get(1).getId());
+        Assert.assertEquals("form1",viewRoot.getChildren().get(2).getId());
+        
+        component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("output2",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("form1",viewRoot.getChildren().get(1).getId());
+        Assert.assertEquals("output1",viewRoot.getChildren().get(2).getId());
+
+        component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("form1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output1",viewRoot.getChildren().get(1).getId());
+        Assert.assertEquals("output2",viewRoot.getChildren().get(2).getId());
+        
+        component = viewRoot.getChildren().remove( 0 );
+        viewRoot.getChildren().add( component );
+
+        viewRoot = saveAndRestore(stateManagement, viewRoot);
+
+        Assert.assertEquals("output1",viewRoot.getChildren().get(0).getId());
+        Assert.assertEquals("output2",viewRoot.getChildren().get(1).getId());
+        Assert.assertEquals("form1",viewRoot.getChildren().get(2).getId());
+
+        Assert.assertEquals("somevalue", viewRoot.getAttributes().get("somekey"));
+        Assert.assertNotNull(viewRoot.findComponent("form1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:foo1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:var1"));
+        Assert.assertNotNull(viewRoot.findComponent("form1:button1"));
         
         a = (HtmlOutputText) viewRoot.findComponent("output1");
-        assertNotNull(a);
-        assertEquals("testOutput1",a.getValue());
+        Assert.assertNotNull(a);
+        Assert.assertEquals("testOutput1",a.getValue());
     }
     
+    public UIViewRoot saveAndRestore(StateManagementStrategy stateManagement, UIViewRoot
viewRoot)
+    {
+        externalContext.getRequestMap()
+        .remove(DefaultFaceletsStateManagementHelper.SERIALIZED_VIEW_REQUEST_ATTR);     
  
+        Object state1 = stateManagement.saveView(facesContext);
+        stateToRestore = state1;
+        facesContext.setViewRoot(null);
+        stateManagement.restoreView(facesContext, "/root", viewRoot.getRenderKitId());
+        return facesContext.getViewRoot();
+    }
     
     public static class MockViewDeclarationLanguage extends ViewDeclarationLanguage
     {



Mime
View raw message