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 2022/12/07 14:06:08 UTC
[myfaces] branch main updated: MYFACES-4523
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/main by this push:
new 3e28b8583 MYFACES-4523
3e28b8583 is described below
commit 3e28b85838f01899849bc506c0808555b1187933
Author: tandraschko <ta...@apache.org>
AuthorDate: Wed Dec 7 15:06:01 2022 +0100
MYFACES-4523
---
.../faces/component/_ComponentAttributesMap.java | 15 ++++++++++++++-
.../api/shared/lang/PropertyDescriptorUtils.java | 21 ++++++++++++++-------
.../api/shared/lang/PropertyDescriptorWrapper.java | 6 ------
.../myfaces/application/ApplicationImpl.java | 20 ++++++++++++++++++--
.../myfaces/el/resolver/LambdaBeanELResolver.java | 19 +++++++++++++++++--
.../view/facelets/tag/BeanPropertyTagRule.java | 22 +++++++++++-----------
.../facelets/tag/LambdaMetadataTargetImpl.java | 14 ++++----------
7 files changed, 78 insertions(+), 39 deletions(-)
diff --git a/api/src/main/java/jakarta/faces/component/_ComponentAttributesMap.java b/api/src/main/java/jakarta/faces/component/_ComponentAttributesMap.java
index f339402ef..e3af4c372 100755
--- a/api/src/main/java/jakarta/faces/component/_ComponentAttributesMap.java
+++ b/api/src/main/java/jakarta/faces/component/_ComponentAttributesMap.java
@@ -31,6 +31,8 @@ import jakarta.el.ValueExpression;
import jakarta.faces.FacesException;
import jakarta.faces.application.Resource;
import jakarta.faces.context.FacesContext;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
import org.apache.myfaces.core.api.shared.lang.Assert;
import org.apache.myfaces.core.api.shared.lang.LambdaPropertyDescriptor;
import org.apache.myfaces.core.api.shared.lang.PropertyDescriptorUtils;
@@ -646,7 +648,11 @@ class _ComponentAttributesMap implements Map<String, Object>, Serializable
{
if (propertyDescriptor instanceof LambdaPropertyDescriptor)
{
- return ((LambdaPropertyDescriptor) propertyDescriptor).getReadFunction().apply(_component);
+ Function<Object, Object> readFunction = ((LambdaPropertyDescriptor) propertyDescriptor).getReadFunction();
+ if (readFunction != null)
+ {
+ return readFunction.apply(_component);
+ }
}
return readMethod.invoke(_component, EMPTY_ARGS);
@@ -679,9 +685,16 @@ class _ComponentAttributesMap implements Map<String, Object>, Serializable
try
{
+ BiConsumer<Object, Object> writeFunction = null;
if (propertyDescriptor instanceof LambdaPropertyDescriptor)
{
((LambdaPropertyDescriptor) propertyDescriptor).getWriteFunction().accept(_component, value);
+ writeFunction = ((LambdaPropertyDescriptor) propertyDescriptor).getWriteFunction();
+ }
+
+ if (writeFunction != null)
+ {
+ writeFunction.accept(_component, value);
}
else
{
diff --git a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java
index bdc96e51e..9b4642609 100644
--- a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java
@@ -138,10 +138,8 @@ public class PropertyDescriptorUtils
for (int i = 0; i < propertyDescriptors.length; i++)
{
PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
- Method readMethod = propertyDescriptor.getReadMethod();
-
map.put(propertyDescriptor.getName(),
- new PropertyDescriptorWrapper(target, propertyDescriptor, readMethod));
+ new PropertyDescriptorWrapper(target, propertyDescriptor));
}
return map;
@@ -184,6 +182,11 @@ public class PropertyDescriptorUtils
public static LambdaPropertyDescriptor createLambdaPropertyDescriptor(Class<?> target, PropertyDescriptor pd,
MethodHandles.Lookup lookup) throws Throwable
{
+ if (pd.getPropertyType() == null)
+ {
+ return null;
+ }
+
LambdaPropertyDescriptor lpd = new LambdaPropertyDescriptor(target, pd);
Method readMethod = pd.getReadMethod();
@@ -209,7 +212,7 @@ public class PropertyDescriptorUtils
return lpd;
}
- public static Map<String, LambdaPropertyDescriptor> getLambdaPropertyDescriptors(Class<?> target) throws Throwable
+ public static Map<String, PropertyDescriptorWrapper> getLambdaPropertyDescriptors(Class<?> target) throws Throwable
{
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(target).getPropertyDescriptors();
if (propertyDescriptors == null || propertyDescriptors.length == 0)
@@ -217,14 +220,18 @@ public class PropertyDescriptorUtils
return Collections.emptyMap();
}
- Map<String, LambdaPropertyDescriptor> properties = new ConcurrentHashMap<>(propertyDescriptors.length);
+ Map<String, PropertyDescriptorWrapper> properties = new ConcurrentHashMap<>(propertyDescriptors.length);
MethodHandles.Lookup lookup = (MethodHandles.Lookup)
privateLookupIn.invoke(null, target, MethodHandles.lookup());
for (PropertyDescriptor pd : Introspector.getBeanInfo(target).getPropertyDescriptors())
{
- LambdaPropertyDescriptor lpd = createLambdaPropertyDescriptor(target, pd, lookup);
- properties.put(pd.getName(), lpd);
+ PropertyDescriptorWrapper wrapped = createLambdaPropertyDescriptor(target, pd, lookup);
+ if (wrapped == null)
+ {
+ wrapped = new PropertyDescriptorWrapper(target, pd);
+ }
+ properties.put(pd.getName(), wrapped);
}
return properties;
diff --git a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorWrapper.java b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorWrapper.java
index fe8193668..e18fbc8d9 100644
--- a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorWrapper.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorWrapper.java
@@ -36,12 +36,6 @@ public class PropertyDescriptorWrapper implements FacesWrapper<PropertyDescripto
this.readMethodRef = new SoftReference<>(wrapped.getReadMethod());
}
- public PropertyDescriptorWrapper(Class<?> beanClass, PropertyDescriptor wrapped, Method readMethod)
- {
- this.wrapped = wrapped;
- this.readMethodRef = new SoftReference<>(readMethod);
- }
-
public Class<?> getPropertyType()
{
return wrapped.getPropertyType();
diff --git a/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java b/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
index 4b7e0c5d0..848aa332b 100755
--- a/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
@@ -84,6 +84,8 @@ import jakarta.faces.render.RendererWrapper;
import jakarta.faces.validator.FacesValidator;
import jakarta.faces.validator.Validator;
import jakarta.faces.view.ViewDeclarationLanguage;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -1581,9 +1583,16 @@ public class ApplicationImpl extends Application
if (!pd.getPropertyType().isPrimitive())
{
Object defaultValue;
+
+ Function<Object, Object> readFunction = null;
if (pd instanceof LambdaPropertyDescriptor)
{
- defaultValue = ((LambdaPropertyDescriptor) pd).getReadFunction().apply(converter);
+ readFunction = ((LambdaPropertyDescriptor) pd).getReadFunction();
+ }
+
+ if (readFunction != null)
+ {
+ defaultValue = readFunction.apply(converter);
}
else
{
@@ -1597,9 +1606,16 @@ public class ApplicationImpl extends Application
}
Object convertedValue = ClassUtils.convertToType(property.getDefaultValue(), pd.getPropertyType());
+
+ BiConsumer<Object, Object> writeFunction = null;
if (pd instanceof LambdaPropertyDescriptor)
{
- ((LambdaPropertyDescriptor) pd).getWriteFunction().accept(converter, convertedValue);
+ writeFunction = ((LambdaPropertyDescriptor) pd).getWriteFunction();
+ }
+
+ if (writeFunction != null)
+ {
+ writeFunction.accept(converter, convertedValue);
}
else
{
diff --git a/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java b/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java
index b07dc77e8..ebe2efa4d 100644
--- a/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java
+++ b/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java
@@ -28,6 +28,8 @@ import jakarta.el.ELException;
import jakarta.el.PropertyNotFoundException;
import jakarta.el.PropertyNotWritableException;
import jakarta.faces.context.FacesContext;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
import org.apache.myfaces.core.api.shared.lang.LambdaPropertyDescriptor;
import org.apache.myfaces.core.api.shared.lang.PropertyDescriptorUtils;
import org.apache.myfaces.core.api.shared.lang.PropertyDescriptorWrapper;
@@ -70,11 +72,18 @@ public class LambdaBeanELResolver extends BeanELResolver
try
{
PropertyDescriptorWrapper pd = getPropertyDescriptor(base, property);
+
+ Function<Object, Object> readFunction = null;
if (pd instanceof LambdaPropertyDescriptor)
{
- return ((LambdaPropertyDescriptor) pd).getReadFunction().apply(base);
+ readFunction = ((LambdaPropertyDescriptor) pd).getReadFunction();
}
+ if (readFunction != null)
+ {
+ return readFunction.apply(base);
+ }
+
return pd.getWrapped().getReadMethod().invoke(base);
}
catch (Exception e)
@@ -104,9 +113,15 @@ public class LambdaBeanELResolver extends BeanELResolver
try
{
+ BiConsumer<Object, Object> writeFunction = null;
if (pd instanceof LambdaPropertyDescriptor)
{
- ((LambdaPropertyDescriptor) pd).getWriteFunction().accept(base, value);
+ writeFunction = ((LambdaPropertyDescriptor) pd).getWriteFunction();
+ }
+
+ if (writeFunction != null)
+ {
+ writeFunction.accept(base, value);
}
else
{
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/BeanPropertyTagRule.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/BeanPropertyTagRule.java
index 8a2293961..b4d71c63f 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/BeanPropertyTagRule.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/BeanPropertyTagRule.java
@@ -41,21 +41,21 @@ public final class BeanPropertyTagRule extends MetaRule
@Override
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
+ BiConsumer<Object, Object> writeFunction = null;
if (meta instanceof LambdaMetadataTargetImpl)
{
- BiConsumer<Object, Object> f = ((LambdaMetadataTargetImpl) meta).getWriteFunction(name);
+ writeFunction = ((LambdaMetadataTargetImpl) meta).getWriteFunction(name);
+ }
- // if the property is writable
- if (f != null)
+ if (writeFunction != null)
+ {
+ if (attribute.isLiteral())
{
- if (attribute.isLiteral())
- {
- return new LiteralPropertyMetadata(meta.getPropertyType(name), f, attribute);
- }
- else
- {
- return new DynamicPropertyMetadata(meta.getPropertyType(name), f, attribute);
- }
+ return new LiteralPropertyMetadata(meta.getPropertyType(name), writeFunction, attribute);
+ }
+ else
+ {
+ return new DynamicPropertyMetadata(meta.getPropertyType(name), writeFunction, attribute);
}
}
else
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/LambdaMetadataTargetImpl.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/LambdaMetadataTargetImpl.java
index 00a5d6248..0149ce7f2 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/LambdaMetadataTargetImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/LambdaMetadataTargetImpl.java
@@ -105,16 +105,10 @@ public class LambdaMetadataTargetImpl extends MetadataTarget
public LambdaPropertyDescriptor getLambdaProperty(String name)
{
- PropertyDescriptorWrapper wrapper = propertyDescriptors.get(name);
-
- if (wrapper instanceof LambdaPropertyDescriptor)
- {
- return (LambdaPropertyDescriptor) wrapper;
- }
- else
- {
- return null;
- }
+ PropertyDescriptorWrapper pdw = propertyDescriptors.get(name);
+ return pdw instanceof LambdaPropertyDescriptor
+ ? (LambdaPropertyDescriptor) pdw
+ : null;
}
public Function<Object, Object> getReadFunction(String name)