Skip to content

Commit

Permalink
Fix #5417: remove "optimization" when composite attribute default is
Browse files Browse the repository at this point in the history
literal instead of VE, this will fail when the final value itself is VE
  • Loading branch information
BalusC committed Mar 16, 2024
1 parent 7cd3d2a commit 402dd2d
Showing 1 changed file with 10 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static jakarta.faces.component.UIComponent.ATTRS_WITH_DECLARED_DEFAULT_VALUES;
import static jakarta.faces.component.UIComponent.BEANINFO_KEY;
import static jakarta.faces.component.UIComponent.COMPOSITE_COMPONENT_TYPE_KEY;
import static java.beans.Introspector.getBeanInfo;
import static java.beans.PropertyEditorManager.findEditor;
import static java.text.MessageFormat.format;
import static java.util.Collections.unmodifiableMap;
Expand All @@ -37,7 +36,6 @@

import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
Expand All @@ -57,16 +55,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.application.ConverterPropertyEditorFactory;
import com.sun.faces.application.ViewMemberInstanceFactoryMetadataMap;
import com.sun.faces.cdi.CdiUtils;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.MessageUtils;
import com.sun.faces.util.ReflectionUtils;
import com.sun.faces.util.Util;

import jakarta.el.ExpressionFactory;
import jakarta.el.ValueExpression;
import jakarta.enterprise.inject.spi.BeanManager;
Expand All @@ -83,6 +71,16 @@
import jakarta.faces.validator.Validator;
import jakarta.faces.view.ViewDeclarationLanguage;

import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.application.ConverterPropertyEditorFactory;
import com.sun.faces.application.ViewMemberInstanceFactoryMetadataMap;
import com.sun.faces.cdi.CdiUtils;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.MessageUtils;
import com.sun.faces.util.ReflectionUtils;
import com.sun.faces.util.Util;

public class InstanceFactory {

// Log instance for this class
Expand Down Expand Up @@ -805,21 +803,12 @@ private void pushDeclaredDefaultValuesToAttributesMap(FacesContext context, Bean
ExpressionFactory expressionFactory) {

Collection<String> attributesWithDeclaredDefaultValues = null;
PropertyDescriptor[] propertyDescriptors = null;

for (PropertyDescriptor propertyDescriptor : componentMetadata.getPropertyDescriptors()) {
Object defaultValue = propertyDescriptor.getValue("default");

if (defaultValue != null) {
String key = propertyDescriptor.getName();
boolean isLiteralText = false;

if (defaultValue instanceof ValueExpression) {
isLiteralText = ((ValueExpression) defaultValue).isLiteralText();
if (isLiteralText) {
defaultValue = ((ValueExpression) defaultValue).getValue(context.getELContext());
}
}

// Ensure this attribute is not a method-signature. method-signature
// declared default values are handled in retargetMethodExpressions.
Expand All @@ -834,24 +823,6 @@ private void pushDeclaredDefaultValuesToAttributesMap(FacesContext context, Bean
}
}
attributesWithDeclaredDefaultValues.add(key);

// Only store the attribute if it is literal text. If it
// is a ValueExpression, it will be handled explicitly in
// CompositeComponentAttributesELResolver.ExpressionEvalMap.get().
// If it is a MethodExpression, it will be dealt with in
// retargetMethodExpressions.
if (isLiteralText) {
try {
if (propertyDescriptors == null) {
propertyDescriptors = getBeanInfo(component.getClass()).getPropertyDescriptors();
}
} catch (IntrospectionException e) {
throw new FacesException(e);
}

defaultValue = convertValueToTypeIfNecessary(key, defaultValue, propertyDescriptors, expressionFactory);
attrs.put(key, defaultValue);
}
}
}
}
Expand Down

0 comments on commit 402dd2d

Please sign in to comment.