You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by GitBox <gi...@apache.org> on 2018/12/05 21:29:07 UTC

[GitHub] wtlucy closed pull request #33: MYFACES-4267 transient template inheritance issue - 2.2.x

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

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 b4c66ae07..8b5d92e7a 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
@@ -2117,25 +2117,22 @@ 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
new file mode 100644
index 000000000..c270b6f5d
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.stateless;
+
+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;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ * @author lu4242
+ */
+public class StatelessTest extends AbstractMyFacesRequestTestCase
+{
+
+    @Override
+    protected boolean isScanAnnotations()
+    {
+        return true;
+    }
+
+    @Override
+    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_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 restoreStatelessTemplateView() throws Exception
+    {
+        startViewRequest("/stateless.xhtml");
+        processLifecycleExecuteAndRender();
+
+        Assert.assertTrue(facesContext.getViewRoot().isTransient());
+
+        // 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);
+
+        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;
+        }
+
+        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
new file mode 100644
index 000000000..f39ceb3df
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
@@ -0,0 +1,24 @@
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:c="http://java.sun.com/jsp/jstl/core"
+                xmlns:h="http://xmlns.jcp.org/jsf/html"
+                xmlns:f="http://xmlns.jcp.org/jsf/core"
+                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+                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">
+                <f:ajax render="@form" execute="@this" />
+            </h:commandButton>
+        </h:form>
+
+        <h:form id="form2">
+            <h:commandButton id="smt" value="Submit" />
+            <h:commandButton id="smtAjax" value="Submit">
+                <f:ajax render="@form" execute="@this" />
+            </h:commandButton>
+        </h:form>
+    </ui:define>
+</ui:composition>
\ No newline at end of file
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/template.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/template.xhtml
new file mode 100644
index 000000000..d32386bd1
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/template.xhtml
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:c="http://java.sun.com/jsp/jstl/core"
+      xmlns:h="http://xmlns.jcp.org/jsf/html"
+      xmlns:f="http://xmlns.jcp.org/jsf/core"
+      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+    <f:view transient="true">
+        <h:head>
+            
+        </h:head>
+        <h:body>
+            <ui:insert name="body" />
+        </h:body>
+    </f:view>
+</html> 
\ No newline at end of file


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services