Skip to content

Commit

Permalink
Fix #5515 by resolving #{cc} using EL instead of CDI
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Feb 1, 2025
1 parent 0d4789a commit 78c482f
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
*/
package com.sun.faces.application;

import jakarta.el.ArrayELResolver;
import jakarta.el.BeanELResolver;
import jakarta.el.ListELResolver;
import jakarta.el.MapELResolver;
import jakarta.el.ResourceBundleELResolver;

import com.sun.faces.context.flash.FlashELResolver;
import com.sun.faces.el.CompositeComponentAttributesELResolver;
import com.sun.faces.el.CompositeComponentELResolver;
import com.sun.faces.el.EmptyStringToNullELResolver;
import com.sun.faces.el.FacesResourceBundleELResolver;
import com.sun.faces.el.ResourceELResolver;
import com.sun.faces.el.ScopedAttributeELResolver;
import jakarta.el.ArrayELResolver;
import jakarta.el.BeanELResolver;
import jakarta.el.ListELResolver;
import jakarta.el.MapELResolver;
import jakarta.el.ResourceBundleELResolver;

public class ResolversRegistry {
public final BeanELResolver BEAN_RESOLVER = new BeanELResolver();
Expand All @@ -37,6 +39,7 @@ public class ResolversRegistry {
public final ResourceBundleELResolver BUNDLE_RESOLVER = new ResourceBundleELResolver();
public final ScopedAttributeELResolver SCOPED_RESOLVER = new ScopedAttributeELResolver();
public final ResourceELResolver RESOURCE_RESOLVER = new ResourceELResolver();
public final CompositeComponentELResolver COMPOSITE_COMPONENT_EL_RESOLVER = new CompositeComponentELResolver();
public final CompositeComponentAttributesELResolver COMPOSITE_COMPONENT_ATTRIBUTES_EL_RESOLVER = new CompositeComponentAttributesELResolver();
public final EmptyStringToNullELResolver EMPTY_STRING_TO_NULL_RESOLVER = new EmptyStringToNullELResolver();

Expand Down
11 changes: 5 additions & 6 deletions impl/src/main/java/com/sun/faces/cdi/CdiExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.sun.faces.push.WebsocketChannelManager;
import com.sun.faces.push.WebsocketSessionManager;
import com.sun.faces.push.WebsocketUserManager;
import com.sun.faces.util.FacesLogger;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
import jakarta.enterprise.inject.spi.AfterDeploymentValidation;
Expand All @@ -50,6 +45,11 @@
import jakarta.faces.model.DataModel;
import jakarta.faces.model.FacesDataModel;

import com.sun.faces.push.WebsocketChannelManager;
import com.sun.faces.push.WebsocketSessionManager;
import com.sun.faces.push.WebsocketUserManager;
import com.sun.faces.util.FacesLogger;

/**
* The CDI extension.
*/
Expand Down Expand Up @@ -181,7 +181,6 @@ public void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery,

afterBeanDiscovery.addBean(new ApplicationProducer());
afterBeanDiscovery.addBean(new ApplicationMapProducer(beanManager));
afterBeanDiscovery.addBean(new CompositeComponentProducer(beanManager));
afterBeanDiscovery.addBean(new ComponentProducer(beanManager));
afterBeanDiscovery.addBean(new FlashProducer(beanManager));
afterBeanDiscovery.addBean(new FlowMapProducer(beanManager));
Expand Down

This file was deleted.

106 changes: 106 additions & 0 deletions impl/src/main/java/com/sun/faces/el/CompositeComponentELResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 1997, 2020 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.el;

import static com.sun.faces.util.Util.getFeatureDescriptor;
import static java.util.Arrays.asList;

import java.beans.FeatureDescriptor;
import java.util.Iterator;

import jakarta.el.ELContext;
import jakarta.el.ELException;
import jakarta.el.ELResolver;
import jakarta.el.PropertyNotWritableException;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.FacesContext;

import com.sun.faces.component.CompositeComponentStackManager;

/**
* <p>
* This {@link ELResolver} will handle the resolution of <code>cc</code> when processing a composite component
* instance.
* </p>
*/
public class CompositeComponentELResolver extends ELResolver {

private static final String COMPOSITE_COMPONENT_NAME = "cc";

@Override
public Object getValue(ELContext context, Object base, Object property) throws ELException {
if (base == null && COMPOSITE_COMPONENT_NAME.equals(property)) {
context.setPropertyResolved(true);
FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
CompositeComponentStackManager manager = CompositeComponentStackManager.getManager(facesContext);
UIComponent currentCompositeComponent = manager.peek();

if (currentCompositeComponent == null) {
currentCompositeComponent = UIComponent.getCurrentCompositeComponent(facesContext);
}

return currentCompositeComponent;
}

return null;
}

@Override
public void setValue(ELContext context, Object base, Object property, Object val) throws ELException {
if (base == null && COMPOSITE_COMPONENT_NAME.equals(property)) {
throw new PropertyNotWritableException((String) property);
}
}

@Override
public boolean isReadOnly(ELContext context, Object base, Object property) throws ELException {
if (base == null && COMPOSITE_COMPONENT_NAME.equals(property)) {
context.setPropertyResolved(true);
return true;
}

return false;
}

@Override
public Class<?> getType(ELContext context, Object base, Object property) throws ELException {
if (base == null && COMPOSITE_COMPONENT_NAME.equals(property)) {
context.setPropertyResolved(true);
return UIComponent.class;
}

return null;
}

@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base != null) {
return null;
}

return String.class;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
if (base != null) {
return null;
}

return asList(getFeatureDescriptor("cc", "cc", "cc", false, false, true, UIComponent.class, Boolean.TRUE)).iterator();
}
}
8 changes: 5 additions & 3 deletions impl/src/main/java/com/sun/faces/el/ELUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import java.util.List;
import java.util.regex.Pattern;

import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.application.ResolversRegistry;
import com.sun.faces.config.WebConfiguration;
import jakarta.el.CompositeELResolver;
import jakarta.el.ELContext;
import jakarta.el.ELResolver;
Expand All @@ -42,6 +39,10 @@
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;

import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.application.ResolversRegistry;
import com.sun.faces.config.WebConfiguration;

/**
* Utility class for EL related methods.
*/
Expand Down Expand Up @@ -149,6 +150,7 @@ public static void buildFacesResolver(FacesCompositeELResolver composite, Applic
addCDIELResolver(composite);
ResolversRegistry elRegistry = associate.getGlobalResolversRegistry();
composite.add(elRegistry.FLASH_RESOLVER);
composite.add(elRegistry.COMPOSITE_COMPONENT_EL_RESOLVER);
composite.addPropertyELResolver(elRegistry.COMPOSITE_COMPONENT_ATTRIBUTES_EL_RESOLVER);
addELResolvers(composite, associate.getELResolversFromFacesConfig());
composite.add(associate.getApplicationELResolvers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.sun.faces.RIConstants;
import com.sun.faces.facelets.el.VariableMapperWrapper;
import com.sun.faces.facelets.tag.MetaRulesetImpl;
import com.sun.faces.facelets.tag.MetadataTargetImpl;
import com.sun.faces.facelets.tag.faces.ComponentTagHandlerDelegateImpl.CreateComponentDelegate;
import com.sun.faces.facelets.util.ReflectionUtil;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.Util;

import jakarta.el.ELException;
import jakarta.el.ValueExpression;
import jakarta.el.VariableMapper;
Expand Down Expand Up @@ -69,6 +60,16 @@
import jakarta.faces.view.facelets.Tag;
import jakarta.faces.view.facelets.TagAttribute;

import com.sun.faces.RIConstants;
import com.sun.faces.el.CompositeComponentELResolver;
import com.sun.faces.facelets.el.VariableMapperWrapper;
import com.sun.faces.facelets.tag.MetaRulesetImpl;
import com.sun.faces.facelets.tag.MetadataTargetImpl;
import com.sun.faces.facelets.tag.faces.ComponentTagHandlerDelegateImpl.CreateComponentDelegate;
import com.sun.faces.facelets.util.ReflectionUtil;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.Util;

/**
* <p>
* Facelet handler responsible for, building the component tree representation of a composite component based on the
Expand Down Expand Up @@ -505,7 +506,7 @@ public void applyMetadata(FaceletContext ctx, Object instance) {
/**
* CompositeExpressionMetadata sets up specialized wrapper ValueExpression instances around the source ValueExpression
* that, when evaluated, will cause the parent composite component of the currently available composite component to be
* pushed onto a stack that the ImplicitObjectELResolver will check for.
* pushed onto a stack that the {@link CompositeComponentELResolver} will check for.
*/
private static final class CompositeExpressionMetadata extends Metadata {

Expand Down

0 comments on commit 78c482f

Please sign in to comment.