[ 
https://issues.apache.org/jira/browse/MYFACES-4267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16710651#comment-16710651
 ] 

ASF GitHub Bot commented on MYFACES-4267:
-----------------------------------------

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

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 cd417632c..20113ff27 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
@@ -2085,24 +2085,22 @@ public UIViewRoot restoreView(FacesContext context, 
String viewId)
                 {
                     view = viewHandler.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);
+
+                    // If the view is not transient, then something is wrong. 
Throw an exception.
+                    if (!view.isTransient())
                     {
-                        context.setProcessingEvents (true);
-                        vdl.buildView (context, view);
+                        throw new FacesException ("unable to create view \"" + 
viewId + "\"");
                     }
-                    finally
-                    {
-                        context.setProcessingEvents(oldContextEventState);
-                    } 
+                }
+                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 d4f070276..fbb7e71b6 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
@@ -20,6 +20,8 @@
 
 import javax.faces.application.StateManager;
 import javax.faces.component.UIComponent;
+import javax.faces.render.ResponseStateManager;
+
 import org.apache.myfaces.config.MyfacesConfig;
 import org.apache.myfaces.test.core.AbstractMyFacesRequestTestCase;
 import org.junit.Assert;
@@ -42,87 +44,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:
us...@infra.apache.org


> transient attribute is not inherited from template to final page.
> -----------------------------------------------------------------
>
>                 Key: MYFACES-4267
>                 URL: https://issues.apache.org/jira/browse/MYFACES-4267
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: Extension Feature
>    Affects Versions: 2.3.2
>            Reporter: Antgar
>            Priority: Major
>             Fix For: 2.3.3, 3.0.0-SNAPSHOT
>
>
> After upgrading from Myfaces 2.2 to 2.3, templated transient views stop to 
> work, raising "unable to create views" exceptions.
> f:view transient attribute defined in a template seems not to be inherited by 
> the final page correctly. With myfaces 2.2 it worked correctly, but in 2.3, 
> there is a new checkĀ 
> {code:java}
> if (!view.isTransient()) ...
> {code}
> on FaceletViewDeclarationLanguage line 2128. On page restoring, transient 
> appears as false.
> A workaround is to set transient="true" on the final page too. Other option 
> is to use a blockĀ 
> {code:java}
> <f:metadata><f:view transient="true" /></f:metadata>
> {code}
> on the final page (f:metadata doc says it shouldn't be used in templates).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to