From 370240d4fe32f4e01637b390591b16567ee22c45 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Mon, 18 May 2020 10:52:45 +0530 Subject: [PATCH 1/4] Spec and OSGi Import package version fix Signed-off-by: Gaurav Gupta --- impl/pom.xml | 10 +++++----- test/pom.xml | 2 +- test/servlet30/facesContextInit/pom.xml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/impl/pom.xml b/impl/pom.xml index fefef5c402..e1a466bd6a 100644 --- a/impl/pom.xml +++ b/impl/pom.xml @@ -297,10 +297,10 @@ org.glassfish.jakarta.faces ${project.version} Mojarra JSF Implementation ${project.version} - Eclipse Faces Implementation (jakarta.faces/2.3) ${project.version} + Eclipse Faces Implementation (jakarta.faces/3.0) ${project.version} Jakarta Server Faces - 2.3 + 3.0 Mojarra ${project.version} @@ -310,8 +310,8 @@ jakarta.faces - jakarta.faces.*;version=2.3, - com.sun.faces.*;version=2.3 + jakarta.faces.*;version=3.0, + com.sun.faces.*;version=3.0 @@ -325,7 +325,7 @@ jakarta.enterprise.util.*, jakarta.enterprise.context.*, jakarta.annotation.processing.*, - jakarta.annotation.*;version="[1.0.0,2.0.0)", + jakarta.annotation.*, javax.crypto.*, jakarta.websocket.*;resolution:=optional, jakarta.json.*;resolution:=optional, diff --git a/test/pom.xml b/test/pom.xml index de15973448..8c26fffcdf 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -155,7 +155,7 @@ jakarta.faces jakarta.faces-api - 2.3.1 + 3.0.0-RC1 provided diff --git a/test/servlet30/facesContextInit/pom.xml b/test/servlet30/facesContextInit/pom.xml index dcd4a4955c..e90616dcc3 100644 --- a/test/servlet30/facesContextInit/pom.xml +++ b/test/servlet30/facesContextInit/pom.xml @@ -34,7 +34,7 @@ jakarta.faces jakarta.faces-api - 2.3.1 + 3.0.0-RC1 provided From b054f7a5bfe8c994da2ebd240d2ce97d118662a6 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Wed, 20 May 2020 13:58:27 +0800 Subject: [PATCH 2/4] Revert "Fix problem introduced in JAVASERVERFACES_SPEC_PUBLIC-1329, also consider Submitted value "" when EMPTY_STRING_AS_NULL_PARAM_NAME is enabled." This reverts commit b3253335366a1d4171f0e066e75c38adbb0755c9. Signed-off-by: Chao Wang --- .../java/jakarta/faces/component/UIInput.java | 20 ++++++++----------- .../faceletsemptyasnull/Issue2827IT.java | 12 +++++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/impl/src/main/java/jakarta/faces/component/UIInput.java b/impl/src/main/java/jakarta/faces/component/UIInput.java index 8f86e47fba..109b42a504 100644 --- a/impl/src/main/java/jakarta/faces/component/UIInput.java +++ b/impl/src/main/java/jakarta/faces/component/UIInput.java @@ -936,9 +936,10 @@ public void validate(FacesContext context) { // If non-null, an instanceof String, and we're configured to treat // zero-length Strings as null: - // call setSubmittedValue(null) - boolean isEmptyStringNull = considerEmptyStringNull(context) && submittedValue instanceof String && ((String) submittedValue).length() == 0; - if (isEmptyStringNull) { + // call setSubmittedValue(null) + if ((considerEmptyStringNull(context) + && submittedValue instanceof String + && ((String) submittedValue).length() == 0)) { setSubmittedValue(null); submittedValue = null; } @@ -959,20 +960,15 @@ public void validate(FacesContext context) { // If our value is valid, store the new value, erase the // "submitted" value, and emit a ValueChangeEvent if appropriate - Object previous = getValue(); - if (isValid() && !isEmptyStringNull) { + if (isValid()) { + Object previous = getValue(); setValue(newValue); setSubmittedValue(null); - } else { - if (submittedValue == null) { - setSubmittedValue(""); + if (compareValues(previous, newValue)) { + queueEvent(new ValueChangeEvent(context, this, previous, newValue)); } } - if (compareValues(previous, newValue)) { - queueEvent(new ValueChangeEvent(context, this, previous, newValue)); - } - } /* diff --git a/test/servlet31/faceletsEmptyAsNull/src/test/java/com/sun/faces/test/servlet31/faceletsemptyasnull/Issue2827IT.java b/test/servlet31/faceletsEmptyAsNull/src/test/java/com/sun/faces/test/servlet31/faceletsemptyasnull/Issue2827IT.java index c7043d5557..7e29b7f884 100644 --- a/test/servlet31/faceletsEmptyAsNull/src/test/java/com/sun/faces/test/servlet31/faceletsemptyasnull/Issue2827IT.java +++ b/test/servlet31/faceletsEmptyAsNull/src/test/java/com/sun/faces/test/servlet31/faceletsemptyasnull/Issue2827IT.java @@ -123,8 +123,8 @@ public void testValidateEmptyFields() throws Exception { pageAsText = page.asText(); assertTrue(pageAsText.contains("VC1 Fired: true")); assertTrue(pageAsText.contains("VC2 Fired: true")); - assertTrue(pageAsText.contains("String model set with null: false")); - assertTrue(pageAsText.contains("Integer model set with null: false")); + assertTrue(pageAsText.contains("String model set with null: true")); + assertTrue(pageAsText.contains("Integer model set with null: true")); submit = (HtmlSubmitInput) page.getHtmlElementById("form:command"); assertNotNull(submit); @@ -143,10 +143,10 @@ public void testValidateEmptyFields() throws Exception { assertEquals(integerInput.getValueAttribute(), ""); pageAsText = page.asText(); - assertTrue(pageAsText.contains("VC1 Fired: true")); - assertTrue(pageAsText.contains("VC2 Fired: true")); - assertTrue(pageAsText.contains("String model set with null: false")); - assertTrue(pageAsText.contains("Integer model set with null: false")); + assertTrue(pageAsText.contains("VC1 Fired: false")); + assertTrue(pageAsText.contains("VC2 Fired: false")); + assertTrue(pageAsText.contains("String model set with null: true")); + assertTrue(pageAsText.contains("Integer model set with null: true")); } } } From 44ea8f05c12cf73881130562df4a27245dc3de92 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Wed, 20 May 2020 14:03:13 +0800 Subject: [PATCH 3/4] Issue 4550 alternative fix, in case of considerEmptyStringNull, call validation diretly in UIInput.java, rather than change submittedValue from null to "" Signed-off-by: Chao Wang --- .../java/jakarta/faces/component/UIInput.java | 4 ++++ .../faces/component/UIViewParameter.java | 19 ------------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/impl/src/main/java/jakarta/faces/component/UIInput.java b/impl/src/main/java/jakarta/faces/component/UIInput.java index 109b42a504..ab691dd3f4 100644 --- a/impl/src/main/java/jakarta/faces/component/UIInput.java +++ b/impl/src/main/java/jakarta/faces/component/UIInput.java @@ -930,6 +930,10 @@ public void validate(FacesContext context) { if (isRequired() && isSetAlwaysValidateRequired(context)) { // continue as below } else { + if(considerEmptyStringNull(context)) { + // https://github.com/eclipse-ee4j/mojarra/issues/4550 + validateValue(context, getConvertedValue(context, submittedValue)); + } return; } } diff --git a/impl/src/main/java/jakarta/faces/component/UIViewParameter.java b/impl/src/main/java/jakarta/faces/component/UIViewParameter.java index a52ad09fdc..6597648357 100644 --- a/impl/src/main/java/jakarta/faces/component/UIViewParameter.java +++ b/impl/src/main/java/jakarta/faces/component/UIViewParameter.java @@ -260,29 +260,10 @@ public void processValidators(FacesContext context) { context.validationFailed(); context.renderResponse(); } else { - if (myConsiderEmptyStringNull(context)) { - // JAVASERVERFACES_SPEC_PUBLIC-1329: If the EMPTY_STRING_SUBMITTED_VALUES_AS_NULL - // config is set, ensure that logic gets a chance to be executed - // in UIInput.processValidators(). - if (null == submittedValue) { - setSubmittedValue(""); - } - } super.processValidators(context); } } - private boolean myConsiderEmptyStringNull(FacesContext ctx) { - - if (emptyStringIsNull == null) { - String val = ctx.getExternalContext().getInitParameter(EMPTY_STRING_AS_NULL_PARAM_NAME); - emptyStringIsNull = Boolean.valueOf(val); - } - - return emptyStringIsNull; - - } - private boolean myIsRequired() { return super.isRequired() || isRequiredViaNestedRequiredValidator(); } From 2ab78c45714442eabeb7571ab91757ee5c98d5eb Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Wed, 20 May 2020 11:22:46 +0800 Subject: [PATCH 4/4] Add a test case for issue 4550 for viewParamNullValueAjax Signed-off-by: Chao Wang (cherry picked from commit 305af850cb3d12e9e016a1749ba98407924f6d71) --- .../java/jakarta/faces/component/UIInput.java | 2 +- test/javaee6/pom.xml | 1 + test/javaee6/viewParamNullValueAjax/pom.xml | 36 ++++++ .../viewParamNullValueAjax/TestView.java | 47 ++++++++ .../src/main/webapp/WEB-INF/beans.xml | 25 ++++ .../src/main/webapp/WEB-INF/glassfish-web.xml | 29 +++++ .../src/main/webapp/WEB-INF/web.xml | 52 +++++++++ .../webapp/viewparam-nullvalue-ajax.xhtml | 53 +++++++++ .../viewParamNullValueAjax/Issue4550IT.java | 107 ++++++++++++++++++ 9 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 test/javaee6/viewParamNullValueAjax/pom.xml create mode 100644 test/javaee6/viewParamNullValueAjax/src/main/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/TestView.java create mode 100644 test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/beans.xml create mode 100644 test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/glassfish-web.xml create mode 100644 test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/web.xml create mode 100644 test/javaee6/viewParamNullValueAjax/src/main/webapp/viewparam-nullvalue-ajax.xhtml create mode 100644 test/javaee6/viewParamNullValueAjax/src/test/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/Issue4550IT.java diff --git a/impl/src/main/java/jakarta/faces/component/UIInput.java b/impl/src/main/java/jakarta/faces/component/UIInput.java index ab691dd3f4..2488e63e44 100644 --- a/impl/src/main/java/jakarta/faces/component/UIInput.java +++ b/impl/src/main/java/jakarta/faces/component/UIInput.java @@ -940,7 +940,7 @@ public void validate(FacesContext context) { // If non-null, an instanceof String, and we're configured to treat // zero-length Strings as null: - // call setSubmittedValue(null) + // call setSubmittedValue(null) if ((considerEmptyStringNull(context) && submittedValue instanceof String && ((String) submittedValue).length() == 0)) { diff --git a/test/javaee6/pom.xml b/test/javaee6/pom.xml index a23d27baaa..e727936179 100644 --- a/test/javaee6/pom.xml +++ b/test/javaee6/pom.xml @@ -38,6 +38,7 @@ correctScanningWar2 resource viewParamBeanValidatorNotNull + viewParamNullValueAjax diff --git a/test/javaee6/viewParamNullValueAjax/pom.xml b/test/javaee6/viewParamNullValueAjax/pom.xml new file mode 100644 index 0000000000..027e3842c9 --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + + pom + com.sun.faces.test.javaee6 + 3.0.0-m01-SNAPSHOT + + + viewParamNullValueAjax + war + Mojarra ${project.version} - Test - JavaEE 6 - viewParameter with null value for Ajax + + + test-javaee6-viewParamNullValueAjax + + + + diff --git a/test/javaee6/viewParamNullValueAjax/src/main/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/TestView.java b/test/javaee6/viewParamNullValueAjax/src/main/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/TestView.java new file mode 100644 index 0000000000..e6c93c56bd --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/src/main/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/TestView.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee6.viewParamNullValueAjax; + +import java.io.Serializable; + +import javax.faces.view.ViewScoped; +import javax.inject.Named; + +@ViewScoped +@Named +public class TestView implements Serializable { + + private String testString; + + public void onView() { + testString = "Test Rhuan"; + System.out.println("initializing: " + testString); + } + + public void someMethod() { + System.out.println(testString); + } + + public String getTestString() { + return testString; + } + + public void setTestString(String testString) { + System.out.println("Setting value: " + testString); + this.testString = testString; + } +} \ No newline at end of file diff --git a/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/beans.xml b/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..802fc5c37e --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/glassfish-web.xml b/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000000..12abdcf0e4 --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,29 @@ + + + + + + /test-javaee6-viewParamNullValueAjax + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/web.xml b/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..ecdebb537a --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,52 @@ + + + + + + javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL + true + + + javax.faces.ENABLE_WEBSOCKET_ENDPOINT + true + + + javax.faces.PROJECT_STAGE + ${webapp.projectStage} + + + javax.faces.PARTIAL_STATE_SAVING + ${webapp.partialStateSaving} + + + javax.faces.STATE_SAVING_METHOD + ${webapp.stateSavingMethod} + + + javax.faces.SERIALIZE_SERVER_STATE + ${webapp.serializeServerState} + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + faces/viewparam-nullvalue-ajax.xhtml + + diff --git a/test/javaee6/viewParamNullValueAjax/src/main/webapp/viewparam-nullvalue-ajax.xhtml b/test/javaee6/viewParamNullValueAjax/src/main/webapp/viewparam-nullvalue-ajax.xhtml new file mode 100644 index 0000000000..2628b1aca9 --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/src/main/webapp/viewparam-nullvalue-ajax.xhtml @@ -0,0 +1,53 @@ + + + + + + + + + + + + issue 4550 viewparameter bug + + + + + + + + +
+ after an ajax request any subsequent call (btn 1 - ajax or btn 2 - non ajax) causes the null value on all view parameters +
+ + + + +
+
+ diff --git a/test/javaee6/viewParamNullValueAjax/src/test/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/Issue4550IT.java b/test/javaee6/viewParamNullValueAjax/src/test/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/Issue4550IT.java new file mode 100644 index 0000000000..3c48022c82 --- /dev/null +++ b/test/javaee6/viewParamNullValueAjax/src/test/java/com/sun/faces/test/javaee6/viewParamNullValueAjax/Issue4550IT.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee6.viewParamNullValueAjax; + +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import com.sun.faces.test.junit.JsfTestRunner; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlPage; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.After; + +@RunWith(JsfTestRunner.class) +public class Issue4550IT { + + private static String TEST_STRING = "Test Rhuan"; + + /** + * Stores the web URL. + */ + private String webUrl; + /** + * Stores the web client. + */ + private WebClient webClient; + + /** + * Setup before testing. + * + * @throws Exception when a serious error occurs. + */ + @BeforeClass + public static void setUpClass() throws Exception { + } + + /** + * Cleanup after testing. + * + * @throws Exception when a serious error occurs. + */ + @AfterClass + public static void tearDownClass() throws Exception { + } + + /** + * Setup before testing. + */ + @Before + public void setUp() { + webUrl = System.getProperty("integration.url"); + webClient = new WebClient(); + } + + @Test + public void testViewParamNullValueAjax() throws Exception { + HtmlPage page = webClient.getPage(webUrl + "faces/viewparam-nullvalue-ajax.xhtml"); + + // Ajax submit click + HtmlSubmitInput submit = (HtmlSubmitInput) page.getHtmlElementById("form:ajaxCommandButton"); + assertNotNull(submit); + page = (HtmlPage) submit.click(); + String pageAsText = page.asText(); + assertTrue(pageAsText.contains(TEST_STRING)); + + // Ajax submit click + submit = (HtmlSubmitInput) page.getHtmlElementById("form:ajaxCommandButton"); + assertNotNull(submit); + page = (HtmlPage) submit.click(); + pageAsText = page.asText(); + assertTrue(pageAsText.contains(TEST_STRING)); + + // Non Ajax submit click + submit = (HtmlSubmitInput) page.getHtmlElementById("form:commandButton"); + assertNotNull(submit); + page = (HtmlPage) submit.click(); + pageAsText = page.asText(); + assertTrue(pageAsText.contains(TEST_STRING)); + } + + @After + public void tearDown() { + webClient.close(); + } +}