Skip to content

Commit

Permalink
Merge pull request #4707 from soul2zimate/issue4550-alternative-3.0
Browse files Browse the repository at this point in the history
Issue4550 alternative 3.0
  • Loading branch information
arjantijms authored Jun 2, 2020
2 parents 21f91d4 + 2ab78c4 commit 8a97e76
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 36 deletions.
22 changes: 11 additions & 11 deletions impl/src/main/java/jakarta/faces/component/UIInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -930,15 +930,20 @@ 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;
}
}

// 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) {
if ((considerEmptyStringNull(context)
&& submittedValue instanceof String
&& ((String) submittedValue).length() == 0)) {
setSubmittedValue(null);
submittedValue = null;
}
Expand All @@ -959,20 +964,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));
}

}

/*
Expand Down
19 changes: 0 additions & 19 deletions impl/src/main/java/jakarta/faces/component/UIViewParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions test/javaee6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<module>correctScanningWar2</module>
<module>resource</module>
<module>viewParamBeanValidatorNotNull</module>
<module>viewParamNullValueAjax</module>
</modules>

</project>
36 changes: 36 additions & 0 deletions test/javaee6/viewParamNullValueAjax/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>pom</artifactId>
<groupId>com.sun.faces.test.javaee6</groupId>
<version>3.0.0-m01-SNAPSHOT</version>
</parent>

<artifactId>viewParamNullValueAjax</artifactId>
<packaging>war</packaging>
<name>Mojarra ${project.version} - Test - JavaEE 6 - viewParameter with null value for Ajax</name>

<build>
<finalName>test-javaee6-viewParamNullValueAjax</finalName>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, 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
-->

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all"
version="1.1">
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<!--
Copyright (c) 2017, 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
-->

<glassfish-web-app error-url="">
<context-root>/test-javaee6-viewParamNullValueAjax</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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 -->

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>${webapp.projectStage}</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>${webapp.partialStateSaving}</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>${webapp.stateSavingMethod}</param-value>
</context-param>
<context-param>
<param-name>javax.faces.SERIALIZE_SERVER_STATE</param-name>
<param-value>${webapp.serializeServerState}</param-value>
</context-param>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/viewparam-nullvalue-ajax.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:metadata>
<f:viewAction action="#{testView.onView}" />
<f:viewParam name="test" value="#{testView.testString}" />
</f:metadata>

<h:head>
<title>issue 4550 viewparameter bug</title>
</h:head>

<h:body>
<h:form id="form">
<h:commandButton id="ajaxCommandButton" value="1. ajax request"
action="#{testView.someMethod()}">
<f:ajax />
</h:commandButton>

<br />
after an ajax request any subsequent call (btn 1 - ajax or btn 2 - non ajax) causes the null value on all view parameters
<br />

<h:commandButton id="commandButton"
value="2. second click causes null value"
action="#{testView.someMethod()}" />

<h:outputText id="testText"
value="the test text valus is #{testView.testString}" />
</h:form>
</h:body>
</html>
Loading

0 comments on commit 8a97e76

Please sign in to comment.