wtlucy closed pull request #32: MYFACES-4267 transient template inheritance 
issue - 2.3.x
URL: https://github.com/apache/myfaces/pull/32
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
 
b/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
index 8ab562dad..693071949 100644
--- 
a/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
+++ 
b/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
@@ -2124,25 +2124,23 @@ public UIViewRoot restoreView(FacesContext context, 
String viewId)
                 {
                     view = 
context.getApplication().getViewHandler().createView(context, viewId);
                 }
-                // If the view is not transient, then something is wrong. 
Throw an exception.
-                if (!view.isTransient())
+                context.setViewRoot (view); 
+                boolean oldContextEventState = context.isProcessingEvents();
+                try 
                 {
-                    throw new FacesException ("unable to create view \"" + 
viewId + "\"");
-                } 
-                else
-                {
-                    context.setViewRoot (view); 
-                    boolean oldContextEventState = 
context.isProcessingEvents();
-                    try 
-                    {
-                        context.setProcessingEvents (true);
-                        vdl.buildView (context, view);
-                    }
-                    finally
+                    context.setProcessingEvents (true);
+                    vdl.buildView (context, view);
+                    // If the view is not transient, then something is wrong. 
Throw an exception.
+                    if (!view.isTransient())
                     {
-                        context.setProcessingEvents (oldContextEventState);
+                        throw new FacesException ("unable to create view \"" + 
viewId + "\"");
                     } 
+    
                 }
+                finally
+                {
+                    context.setProcessingEvents (oldContextEventState);
+                } 
             }
             catch (Throwable e)
             {
diff --git 
a/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
 
b/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
index 18e5eac83..9c937e9f1 100644
--- 
a/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
+++ 
b/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
@@ -21,6 +21,8 @@
 import javax.faces.application.StateManager;
 import javax.faces.component.UICommand;
 import javax.faces.component.UIComponent;
+import javax.faces.render.ResponseStateManager; 
+
 import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
 import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.junit.Assert;
@@ -45,87 +47,47 @@ protected void setUpWebConfigParams() throws Exception
     {
         super.setUpWebConfigParams();
         
servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.stateless");
-        
servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, 
StateManager.STATE_SAVING_METHOD_CLIENT);
+        
servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, 
StateManager.STATE_SAVING_METHOD_SERVER);
         servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", 
"true");
         
servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS,
 "auto");
         
servletContext.addInitParameter("org.apache.myfaces.STRICT_JSF_2_REFRESH_TARGET_AJAX",
 "true");
     }
     
+    /**
+     * Verify that a view with a template that has transient set can be 
restored
+     * 
+     * @throws Exception
+     */
     @Test
-    public void postWithoutPrependFormId() throws Exception
+    public void restoreStatelessTemplateView() throws Exception
     {
         startViewRequest("/stateless.xhtml");
         processLifecycleExecuteAndRender();
-        
-        Assert.assertTrue(facesContext.getViewRoot().isTransient());
-        
-        UIComponent form = facesContext.getViewRoot().findComponent("form1");
-        UIComponent formButton = 
facesContext.getViewRoot().findComponent("form1:smt");
-        
-        client.submit(formButton);
-        
-        processLifecycleExecuteAndRender();
-        String text = getRenderedContent(facesContext);
 
-        endRequest();
-    }
-    
-    @Test
-    public void postAjaxWithoutPrependFormId() throws Exception
-    {
-        startViewRequest("/stateless.xhtml");
-        processLifecycleExecuteAndRender();
-        
         Assert.assertTrue(facesContext.getViewRoot().isTransient());
-        
-        UIComponent form = facesContext.getViewRoot().findComponent("form1");
-        UIComponent formButton = 
facesContext.getViewRoot().findComponent("form1:smtAjax");
-        
-        client.ajax(formButton, "action", 
formButton.getClientId(facesContext), form.getClientId(facesContext), true);
-        
-        processLifecycleExecuteAndRender();
-        String text = getRenderedContent(facesContext);
 
-        endRequest();
-    }
-    
-    @Test
-    public void postWithPrependFormId() throws Exception
-    {
-        startViewRequest("/stateless.xhtml");
-        processLifecycleExecuteAndRender();
-        
-        Assert.assertTrue(facesContext.getViewRoot().isTransient());
-        
-        UIComponent form = facesContext.getViewRoot().findComponent("form2");
-        UIComponent formButton = 
facesContext.getViewRoot().findComponent("form2:smt");
-        
+        // set the view state param so this context is treated as a postback
+        client.getParameters().put(ResponseStateManager.VIEW_STATE_PARAM, 
"stateless");
+        UIComponent formButton = 
facesContext.getViewRoot().findComponent("smt");
         client.submit(formButton);
-        
-        processLifecycleExecuteAndRender();
-        String text = getRenderedContent(facesContext);
 
-        endRequest();
-    }
+        try {
+            // this will cause an exception without the fix in MYFACES-4267
+            restoreView();
+        } catch (Exception e) {
+            Assert.fail("caught an exception trying to restore a stateless 
view: " + e.getMessage());
+            endRequest();
+            return;
+        }
 
-    @Test
-    public void postAjaxWithPrependFormId() throws Exception
-    {
-        startViewRequest("/stateless.xhtml");
-        processLifecycleExecuteAndRender();
-        
-        Assert.assertTrue(facesContext.getViewRoot().isTransient());
-        
-        UIComponent form = facesContext.getViewRoot().findComponent("form2");
-        UIComponent formButton = 
facesContext.getViewRoot().findComponent("form2:smtAjax");
-        
-        client.ajax(formButton, "action", 
formButton.getClientId(facesContext), form.getClientId(facesContext), true);
-        
-        processLifecycleExecuteAndRender();
+        Assert.assertNotNull(facesContext.getViewRoot());
+
+        // render the response and make sure the view contains the expected 
text
+        renderResponse();
         String text = getRenderedContent(facesContext);
 
+        Assert.assertTrue(text.contains("success"));
+
         endRequest();
     }
-    
-    
 }
diff --git 
a/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
 
b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
index 6388315ad..54e301b88 100644
--- 
a/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
+++ 
b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
@@ -6,7 +6,7 @@
                 template="template.xhtml">
 
     <ui:define name="body">
-
+        success!
         <h:form id="form1" prependId="false">
             <h:commandButton id="smt" value="Submit" />
             <h:commandButton id="smtAjax" value="Submit">


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to