You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2020/06/18 11:41:38 UTC
[myfaces] branch master updated: MYFACES-4342
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new 22c1e39 MYFACES-4342
22c1e39 is described below
commit 22c1e3946f026f4ec3fec947ae5d33c8193add1b
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Thu Jun 18 13:41:30 2020 +0200
MYFACES-4342
---
.../extensions/quarkus/showcase/view/LazyView.java | 15 +++++
.../main/resources/META-INF/resources/issue4.xhtml | 3 +-
.../showcase/src/main/resources/META-INF/web.xml | 5 +-
.../myfaces/el/ELResolverBuilderForFaces.java | 8 +++
.../el/resolver/EmptyStringToNullELResolver.java | 74 ++++++++++++++++++++++
5 files changed, 103 insertions(+), 2 deletions(-)
diff --git a/extensions/quarkus/showcase/src/main/java/org/apache/myfaces/core/extensions/quarkus/showcase/view/LazyView.java b/extensions/quarkus/showcase/src/main/java/org/apache/myfaces/core/extensions/quarkus/showcase/view/LazyView.java
index e83e5d9..1de3971 100644
--- a/extensions/quarkus/showcase/src/main/java/org/apache/myfaces/core/extensions/quarkus/showcase/view/LazyView.java
+++ b/extensions/quarkus/showcase/src/main/java/org/apache/myfaces/core/extensions/quarkus/showcase/view/LazyView.java
@@ -36,6 +36,8 @@ public class LazyView implements Serializable {
private Car selectedCar;
+ private String inputVal;
+
@Inject
CarService service;
@@ -64,4 +66,17 @@ public class LazyView implements Serializable {
FacesMessage msg = new FacesMessage("Car Selected", ((Car) event.getObject()).getId());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
+
+ public String getInputVal() {
+ return inputVal;
+ }
+
+ public void setInputVal(String inputVal) {
+ this.inputVal = inputVal;
+ }
+
+ public void saveInput() {
+ System.out.println("Input val is: " + inputVal);
+ System.out.println("Input val is null?" + (inputVal == null));
+ }
}
diff --git a/extensions/quarkus/showcase/src/main/resources/META-INF/resources/issue4.xhtml b/extensions/quarkus/showcase/src/main/resources/META-INF/resources/issue4.xhtml
index 7c1cd69..60629c1 100644
--- a/extensions/quarkus/showcase/src/main/resources/META-INF/resources/issue4.xhtml
+++ b/extensions/quarkus/showcase/src/main/resources/META-INF/resources/issue4.xhtml
@@ -29,7 +29,8 @@
<h:body>
<h:form id="form">
- <p:commandButton value="property action listener">
+ <p:inputText style="width:100%;" value="#{dtLazyView.inputVal}" />
+ <p:commandButton value="property action listener" actionListener="#{dtLazyView.saveInput()}">
<f:setPropertyActionListener value="true"
target="#{facesContext.externalContext.flash.keepMessages}"/>
</p:commandButton>
diff --git a/extensions/quarkus/showcase/src/main/resources/META-INF/web.xml b/extensions/quarkus/showcase/src/main/resources/META-INF/web.xml
index 35816fa..f4e2e8a 100644
--- a/extensions/quarkus/showcase/src/main/resources/META-INF/web.xml
+++ b/extensions/quarkus/showcase/src/main/resources/META-INF/web.xml
@@ -25,8 +25,11 @@
<param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
<param-value>true</param-value>
</context-param>
+ <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>primefaces.THEME</param-name>
<param-value>luna-amber</param-value>
diff --git a/impl/src/main/java/org/apache/myfaces/el/ELResolverBuilderForFaces.java b/impl/src/main/java/org/apache/myfaces/el/ELResolverBuilderForFaces.java
index fee0cca..958b066 100644
--- a/impl/src/main/java/org/apache/myfaces/el/ELResolverBuilderForFaces.java
+++ b/impl/src/main/java/org/apache/myfaces/el/ELResolverBuilderForFaces.java
@@ -33,6 +33,7 @@ import javax.el.ListELResolver;
import javax.el.MapELResolver;
import javax.el.ResourceBundleELResolver;
import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import org.apache.myfaces.cdi.util.CDIUtils;
@@ -47,6 +48,7 @@ import org.apache.myfaces.el.resolver.ScopedAttributeResolver;
import org.apache.myfaces.el.resolver.implicitobject.ImplicitObjectResolver;
import org.apache.myfaces.config.MyfacesConfig;
import org.apache.myfaces.core.api.shared.lang.PropertyDescriptorUtils;
+import org.apache.myfaces.el.resolver.EmptyStringToNullELResolver;
import org.apache.myfaces.el.resolver.LambdaBeanELResolver;
import org.apache.myfaces.util.lang.ClassUtils;
@@ -107,6 +109,12 @@ public class ELResolverBuilderForFaces extends ELResolverBuilder
addFromRuntimeConfig(list);
+ if ("true".equalsIgnoreCase(
+ facesContext.getExternalContext().getInitParameter(UIInput.EMPTY_STRING_AS_NULL_PARAM_NAME)))
+ {
+ list.add(new EmptyStringToNullELResolver());
+ }
+
//Flash object is instanceof Map, so it is necessary to resolve
//before MapELResolver. Better to put this one before
list.add(new FlashELResolver());
diff --git a/impl/src/main/java/org/apache/myfaces/el/resolver/EmptyStringToNullELResolver.java b/impl/src/main/java/org/apache/myfaces/el/resolver/EmptyStringToNullELResolver.java
new file mode 100644
index 0000000..f6752eb
--- /dev/null
+++ b/impl/src/main/java/org/apache/myfaces/el/resolver/EmptyStringToNullELResolver.java
@@ -0,0 +1,74 @@
+/*
+ * 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.el.resolver;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+public class EmptyStringToNullELResolver extends ELResolver
+{
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base)
+ {
+ return String.class;
+ }
+
+ @Override
+ public Object convertToType(ELContext context, Object value, Class<?> targetType)
+ {
+ if (value == null && targetType == String.class)
+ {
+ context.setPropertyResolved(true);
+ }
+
+ return value;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
+ {
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property)
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
+ return true;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ {
+ // NOOP.
+ }
+}