Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Commit

Permalink
[port 2.2.x] JAVASERVERFACES-4073
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xinyuan-zhang committed Jun 15, 2017
1 parent f55bb27 commit e8bd403
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:t="http://java.sun.com/jsf/composite/t">

<h:head>
</h:head>
<h:body>
<f:view>
<f:event type="preRenderView" listener="#{managedBean.initialize}" />
<h:form prependId="false">
<ui:insert name="content"></ui:insert>
<h:outputText id="button2value" value="#{managedBean.button2SetValue}">
</h:outputText>
</h:form>

</f:view>
</h:body>
</html>
13 changes: 13 additions & 0 deletions test/javaee6web/facelets/src/main/webapp/WEB-INF/xhtml/parts.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:t="http://java.sun.com/jsf/composite/t">

<t:comp id="comp_id" value="#{param2}" action1="#{managedBean.button2(param3)}" />
<br />

</ui:composition>
26 changes: 26 additions & 0 deletions test/javaee6web/facelets/src/main/webapp/issue4073.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:t="http://java.sun.com/jsf/composite/t">

<ui:composition template="/WEB-INF/template/template.xhtml">

<f:metadata>
<ui:param name="managedBean" value="#{sampleMBean}" />
</f:metadata>

<ui:define name="content">
<ui:decorate template="/WEB-INF/xhtml/parts.xhtml">
<ui:param name="managedBean" value="#{managedBean}" />
<ui:param name="param1" value="TEST 1" />
<ui:param name="param2" value="TEST 2" />
<ui:param name="param3" value="#{managedBean.text}" />
</ui:decorate>
</ui:define>

</ui:composition>
</html>
22 changes: 22 additions & 0 deletions test/javaee6web/facelets/src/main/webapp/resources/t/comp.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>

<composite:attribute name="action1" shortDescription="action1" method-signature="java.lang.String action()" />
<composite:attribute name="value" shortDescription="value" />

</composite:interface>

<composite:implementation>

<h:commandButton id="Button_id" value="#{cc.attrs.value}" action="#{cc.attrs.action1}" />

</composite:implementation>

</html>
Original file line number Diff line number Diff line change
@@ -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"));
}

}

0 comments on commit e8bd403

Please sign in to comment.