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 2015/03/25 17:58:37 UTC
svn commit: r1669157 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/view/facelets/
test/java/org/apache/myfaces/view/facelets/pool/
test/resources/org/apache/myfaces/view/facelets/pool/
Author: lu4242
Date: Wed Mar 25 16:58:36 2015
New Revision: 1669157
URL: http://svn.apache.org/r1669157
Log:
MYFACES-3967 View Pooling - ViewScope missing for Static Structure Views
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pool/ViewPoolMyFacesRequestTestCase.java
myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pool/staticPage3.xhtml
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java?rev=1669157&r1=1669156&r2=1669157&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java Wed Mar 25 16:58:36 2015
@@ -321,12 +321,24 @@ public class ViewPoolProcessor
UIViewRoot oldView = entry.getViewRoot();
// retrieveViewRootInitialState(context, oldView)
Object viewState = metadata.getViewRootState();
+ Object newViewState;
+ UIComponent metadataFacet = newView.getFacet(UIViewRoot.METADATA_FACET_NAME);
if (viewState == null)
{
// (Optional, it should be always metadata)
oldView.clearInitialState();
viewState = oldView.saveState(context);
}
+ Map<String, Object> viewScopeMap = newView.getViewMap(false);
+ if (viewScopeMap != null && !viewScopeMap.isEmpty())
+ {
+ newViewState = newView.saveState(context);
+ }
+ else
+ {
+ newViewState = null;
+ }
+
boolean oldProcessingEvents = context.isProcessingEvents();
context.setProcessingEvents(false);
try
@@ -338,9 +350,22 @@ public class ViewPoolProcessor
for (String facetKey : facetKeys)
{
//context.setProcessingEvents(false);
- UIComponent facet = oldView.getFacets().remove(facetKey);
- //context.setProcessingEvents(true);
- newView.getFacets().put(facetKey, facet);
+ if (metadataFacet != null && UIViewRoot.METADATA_FACET_NAME.equals(facetKey) &&
+ !PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()))
+ {
+ // Metadata facet is special, it is created when ViewHandler.createView(...) is
+ // called, so it shouldn't be taken from the oldView, otherwise the state
+ // will be lost. Instead reuse it and discard the one in oldView.
+ // But on restore view phase, use the old one, because the new one does not
+ // have initial state marked.
+ newView.getFacets().put(facetKey, metadataFacet);
+ }
+ else
+ {
+ UIComponent facet = oldView.getFacets().remove(facetKey);
+ //context.setProcessingEvents(true);
+ newView.getFacets().put(facetKey, facet);
+ }
}
}
if (oldView.getChildCount() > 0)
@@ -364,6 +389,27 @@ public class ViewPoolProcessor
// Restore bindings like in restore view phase, because in this case,
// bindings needs to be set (Application.createComponent is not called!).
restoreViewSupport.processComponentBinding(context, newView);
+
+ // Restore view scope map if necessary
+ if (viewScopeMap != null && !viewScopeMap.isEmpty())
+ {
+ Map<String, Object> newViewScopeMap = newView.getViewMap(false);
+ if (newViewScopeMap == null)
+ {
+ newView.restoreViewScopeState(context, newViewState);
+ }
+ else
+ {
+ // Should theoretically not happen, because when a pooled static view
+ // is saved, the view scope map is skipped, otherwise it could be a
+ // leak. Anyway, we let this code here that overrides the values from
+ // the original map.
+ for (Map.Entry<String, Object> entry2 : viewScopeMap.entrySet())
+ {
+ newViewScopeMap.put(entry2.getKey(), entry2.getValue());
+ }
+ }
+ }
}
// Update request view metadata to ensure resource list is restored as when the
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pool/ViewPoolMyFacesRequestTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pool/ViewPoolMyFacesRequestTestCase.java?rev=1669157&r1=1669156&r2=1669157&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pool/ViewPoolMyFacesRequestTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pool/ViewPoolMyFacesRequestTestCase.java Wed Mar 25 16:58:36 2015
@@ -29,7 +29,9 @@ import javax.faces.component.UIComponent
import javax.faces.component.UIForm;
import javax.faces.component.UIOutput;
import javax.faces.component.UIPanel;
+import javax.faces.component.UIViewParameter;
import javax.faces.component.UIViewRoot;
+import javax.faces.view.ViewMetadata;
import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
import org.apache.myfaces.shared.config.MyfacesConfig;
@@ -440,12 +442,14 @@ public class ViewPoolMyFacesRequestTestC
startViewRequest("/staticPage3.xhtml");
processLifecycleExecute();
locale = facesContext.getViewRoot().getLocale();
+ facesContext.getViewRoot().getViewMap().put("keyBeforeView", "someBeforeValue");
+
executeBeforeRender(facesContext);
executeBuildViewCycle(facesContext);
// Use view scope
+ Assert.assertEquals("someBeforeValue", facesContext.getViewRoot().getViewMap().get("keyBeforeView"));
facesContext.getViewRoot().getViewMap().put("someKey", "someValue");
- Assert.assertEquals("viewValue", facesContext.getViewRoot().getViewMap().get("viewKey"));
UICommand submitButton = (UICommand) facesContext.getViewRoot().findComponent("mainForm:submit");
@@ -461,7 +465,6 @@ public class ViewPoolMyFacesRequestTestC
//Check if the view scope value is preserved
Assert.assertEquals("someValue", facesContext.getViewRoot().getViewMap().get("someKey"));
- Assert.assertEquals("viewValue", facesContext.getViewRoot().getViewMap().get("viewKey"));
facesContext.getViewRoot().getViewMap().put("someKey", "someValue2");
@@ -479,7 +482,6 @@ public class ViewPoolMyFacesRequestTestC
//Check if the view scope value is preserved
Assert.assertEquals("someValue2", facesContext.getViewRoot().getViewMap().get("someKey"));
- Assert.assertEquals("viewValue", facesContext.getViewRoot().getViewMap().get("viewKey"));
Assert.assertTrue(facesContext.getViewRoot().getChildCount() > 0);
@@ -501,6 +503,54 @@ public class ViewPoolMyFacesRequestTestC
}
@Test
+ public void testStaticPage1_7() throws Exception
+ {
+ Locale locale = null;
+ startViewRequest("/staticPage3.xhtml");
+ processLifecycleExecute();
+ locale = facesContext.getViewRoot().getLocale();
+
+ executeBeforeRender(facesContext);
+ executeBuildViewCycle(facesContext);
+
+ // Use view scope
+ facesContext.getViewRoot().getViewMap().put("someKey", "someValue");
+ //Assert.assertEquals("viewValue", facesContext.getViewRoot().getViewMap().get("viewKey"));
+
+ executeViewHandlerRender(facesContext);
+ executeAfterRender(facesContext);
+
+ startViewRequest("/staticPage3.xhtml");
+ request.addParameter("id", "someId");
+ processLifecycleExecute();
+ locale = facesContext.getViewRoot().getLocale();
+ facesContext.getViewRoot().getViewMap().put("keyBeforeView", "someBeforeValue");
+
+ UIViewParameter paramComponent = ViewMetadata.getViewParameters(facesContext.getViewRoot()).iterator().next();
+ Assert.assertNotNull(paramComponent);
+ Assert.assertEquals("someId", paramComponent.getValue());
+
+ executeBeforeRender(facesContext);
+ executeBuildViewCycle(facesContext);
+
+ paramComponent = ViewMetadata.getViewParameters(facesContext.getViewRoot()).iterator().next();
+ Assert.assertNotNull(paramComponent);
+ Assert.assertEquals("someId", paramComponent.getValue());
+
+ // Use view scope
+ Assert.assertEquals("someBeforeValue", facesContext.getViewRoot().getViewMap().get("keyBeforeView"));
+ facesContext.getViewRoot().getViewMap().put("someKey", "someValue");
+ //Assert.assertEquals("viewValue", facesContext.getViewRoot().getViewMap().get("viewKey"));
+
+ UICommand submitButton = (UICommand) facesContext.getViewRoot().findComponent("mainForm:submit");
+
+ executeViewHandlerRender(facesContext);
+ executeAfterRender(facesContext);
+
+ endRequest();
+ }
+
+ @Test
public void testStaticPage2() throws Exception
{
Locale locale = null;
Modified: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pool/staticPage3.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pool/staticPage3.xhtml?rev=1669157&r1=1669156&r2=1669157&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pool/staticPage3.xhtml (original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pool/staticPage3.xhtml Wed Mar 25 16:58:36 2015
@@ -26,11 +26,13 @@
<head>
<title>Test Static Page</title>
</head>
+ <f:metadata>
+ <f:viewParam name="id"/>
+ </f:metadata>
<body>
<div id="container">
<h1>Test cache of static page</h1>
<!-- <h:messages showDetail="true" showSummary="false"/> -->
- <c:set var="viewKey" value="viewValue" scope="view" />
<h:form id="mainForm">
<h:panelGrid id="testGroup1" columns="2">
<h:outputLabel for="name" value="Please enter your name"/>