From e8bd4033d20dcc2a54d8fda37ec95e23043eec2d Mon Sep 17 00:00:00 2001 From: xinyuan-zhang Date: Thu, 15 Jun 2017 14:37:02 +0800 Subject: [PATCH] [port 2.2.x] JAVASERVERFACES-4073 https://github.com/javaserverfaces/mojarra/issues/4103 The parameter is not passed to h:commandButton defined as composite component modified: jsf-ri/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java new file: test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/Issue4073Bean.java new file: test/javaee6web/facelets/src/main/webapp/WEB-INF/template/template.xhtml new file: test/javaee6web/facelets/src/main/webapp/WEB-INF/xhtml/parts.xhtml new file: test/javaee6web/facelets/src/main/webapp/issue4073.xhtml new file: test/javaee6web/facelets/src/main/webapp/resources/t/comp.xhtml new file: test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue4073IT.java --- .../view/FaceletViewHandlingStrategy.java | 14 ++-- .../javaee6web/facelets/Issue4073Bean.java | 40 ++++++++++ .../webapp/WEB-INF/template/template.xhtml | 23 ++++++ .../src/main/webapp/WEB-INF/xhtml/parts.xhtml | 13 +++ .../facelets/src/main/webapp/issue4073.xhtml | 26 ++++++ .../src/main/webapp/resources/t/comp.xhtml | 22 ++++++ .../test/javaee6web/facelets/Issue4073IT.java | 79 +++++++++++++++++++ 7 files changed, 212 insertions(+), 5 deletions(-) create mode 100644 test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/Issue4073Bean.java create mode 100644 test/javaee6web/facelets/src/main/webapp/WEB-INF/template/template.xhtml create mode 100644 test/javaee6web/facelets/src/main/webapp/WEB-INF/xhtml/parts.xhtml create mode 100644 test/javaee6web/facelets/src/main/webapp/issue4073.xhtml create mode 100644 test/javaee6web/facelets/src/main/webapp/resources/t/comp.xhtml create mode 100644 test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue4073IT.java diff --git a/jsf-ri/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java b/jsf-ri/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java index e7b6b5ebef..d1cca15e55 100644 --- a/jsf-ri/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java +++ b/jsf-ri/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java @@ -45,6 +45,8 @@ import com.sun.faces.config.WebConfiguration; import com.sun.faces.config.WebConfiguration.WebContextInitParameter; import com.sun.faces.context.StateContext; + +import javax.el.*; import javax.faces.view.facelets.Facelet; import com.sun.faces.facelets.el.ContextualCompositeMethodExpression; import com.sun.faces.facelets.el.VariableMapperWrapper; @@ -72,10 +74,6 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import javax.el.ExpressionFactory; -import javax.el.MethodExpression; -import javax.el.ValueExpression; -import javax.el.VariableMapper; import javax.faces.FacesException; import javax.faces.FactoryFinder; import javax.faces.application.Resource; @@ -1983,8 +1981,14 @@ public void retarget(FacesContext ctx, CompCompInterfaceMethodMetadata metadata, assert (null != expectedReturnType); assert (null != expectedParameters); + // JAVASERVERFACES-4073 + ELContext elContext = (ELContext) ctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); + if (null == elContext) { + elContext = ctx.getELContext(); + } + MethodExpression me = f - .createMethodExpression(ctx.getELContext(), + .createMethodExpression(elContext , ve.getExpressionString(), expectedReturnType, expectedParameters); diff --git a/test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/Issue4073Bean.java b/test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/Issue4073Bean.java new file mode 100644 index 0000000000..a8fdc8787e --- /dev/null +++ b/test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/Issue4073Bean.java @@ -0,0 +1,40 @@ +package com.sun.faces.test.javaee6web.facelets; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; + +@Named("sampleMBean") +@SessionScoped +public class Issue4073Bean implements Serializable { + private String button2SetValue; + + public String getButton2SetValue() { + return button2SetValue; + } + + public void setButton2SetValue(String button2SetValue) { + this.button2SetValue = button2SetValue; + } + + public void initialize() { + System.out.println("# called initialize()"); + } + + public String button1() { + System.out.println("# called button1()"); + return null; + } + + public String button2(String value) { + System.out.println("# called button2() value=" + value); + button2SetValue = value; + return null; + } + + public String getText() { + return "Hello World"; + } + +} diff --git a/test/javaee6web/facelets/src/main/webapp/WEB-INF/template/template.xhtml b/test/javaee6web/facelets/src/main/webapp/WEB-INF/template/template.xhtml new file mode 100644 index 0000000000..4afe27dc6a --- /dev/null +++ b/test/javaee6web/facelets/src/main/webapp/WEB-INF/template/template.xhtml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/test/javaee6web/facelets/src/main/webapp/WEB-INF/xhtml/parts.xhtml b/test/javaee6web/facelets/src/main/webapp/WEB-INF/xhtml/parts.xhtml new file mode 100644 index 0000000000..19da291517 --- /dev/null +++ b/test/javaee6web/facelets/src/main/webapp/WEB-INF/xhtml/parts.xhtml @@ -0,0 +1,13 @@ + + + + + +
+ +
diff --git a/test/javaee6web/facelets/src/main/webapp/issue4073.xhtml b/test/javaee6web/facelets/src/main/webapp/issue4073.xhtml new file mode 100644 index 0000000000..e66a693d34 --- /dev/null +++ b/test/javaee6web/facelets/src/main/webapp/issue4073.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/test/javaee6web/facelets/src/main/webapp/resources/t/comp.xhtml b/test/javaee6web/facelets/src/main/webapp/resources/t/comp.xhtml new file mode 100644 index 0000000000..e92e9843d8 --- /dev/null +++ b/test/javaee6web/facelets/src/main/webapp/resources/t/comp.xhtml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue4073IT.java b/test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue4073IT.java new file mode 100644 index 0000000000..134185da40 --- /dev/null +++ b/test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue4073IT.java @@ -0,0 +1,79 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package com.sun.faces.test.javaee6web.facelets; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import com.gargoylesoftware.htmlunit.html.HtmlTextInput; +import com.sun.faces.test.junit.JsfTestRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.runner.RunWith; + +@RunWith(JsfTestRunner.class) +public class Issue4073IT { + + private String webUrl; + private WebClient webClient; + + @Before + public void setUp() { + webUrl = System.getProperty("integration.url"); + webClient = new WebClient(); + } + + @After + public void tearDown() { + webClient.closeAllWindows(); + } + + @Test + public void testButton2SetValueNotNull() throws Exception { + HtmlPage page = webClient.getPage(webUrl + "faces/issue4073.xhtml"); + HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("comp_id:Button_id"); + page = button.click(); + + assertTrue(page.asText().contains("Hello World")); + } + +}