Skip to content

Commit

Permalink
Merge #5460, #5464 and #5468 from 4.1 into 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Aug 3, 2024
2 parents 2a0e8fc + 968bdf7 commit a019325
Show file tree
Hide file tree
Showing 35 changed files with 263 additions and 364 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -840,25 +840,6 @@ private void pushDeclaredDefaultValuesToAttributesMap(FacesContext context, Bean
}
}

/**
* Helper method to convert a value to a type as defined in PropertyDescriptor(s)
*
* @param name
* @param value
* @param propertyDescriptors
* @return value
*/
private Object convertValueToTypeIfNecessary(String name, Object value, PropertyDescriptor[] propertyDescriptors, ExpressionFactory expressionFactory) {
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor.getName().equals(name)) {
value = expressionFactory.coerceToType(value, propertyDescriptor.getPropertyType());
break;
}
}

return value;
}

/**
* <p>
* To enable EL Coercion to use Faces Custom converters, this method will call
Expand Down
12 changes: 8 additions & 4 deletions impl/src/main/java/com/sun/faces/cdi/ApplicationMapProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.faces.annotation.ApplicationMap;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
Expand All @@ -40,10 +41,13 @@ public class ApplicationMapProducer extends CdiProducer<Map<String, Object>> {
*/
private static final long serialVersionUID = 1L;

public ApplicationMapProducer() {
super.name("applicationScope").scope(ApplicationScoped.class).qualifiers(ApplicationMap.Literal.INSTANCE)
.types(new ParameterizedTypeImpl(Map.class, new Type[] { String.class, Object.class }), Map.class, Object.class)
.create(e -> FacesContext.getCurrentInstance().getExternalContext().getApplicationMap());
public ApplicationMapProducer(BeanManager beanManager) {
super.name("applicationScope")
.scope(ApplicationScoped.class)
.qualifiers(ApplicationMap.Literal.INSTANCE)
.beanClass(beanManager, Map.class)
.types(new ParameterizedTypeImpl(Map.class, new Type[] { String.class, Object.class }), Map.class, Object.class)
.create(e -> FacesContext.getCurrentInstance().getExternalContext().getApplicationMap());
}

}
40 changes: 20 additions & 20 deletions impl/src/main/java/com/sun/faces/cdi/CdiExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,28 @@ public void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery,
// but this is not detectable as ServletContext is not necessarily available at this moment.

afterBeanDiscovery.addBean(new ApplicationProducer());
afterBeanDiscovery.addBean(new ApplicationMapProducer());
afterBeanDiscovery.addBean(new CompositeComponentProducer());
afterBeanDiscovery.addBean(new ComponentProducer());
afterBeanDiscovery.addBean(new FlashProducer());
afterBeanDiscovery.addBean(new FlowProducer());
afterBeanDiscovery.addBean(new FlowMapProducer());
afterBeanDiscovery.addBean(new HeaderMapProducer());
afterBeanDiscovery.addBean(new HeaderValuesMapProducer());
afterBeanDiscovery.addBean(new InitParameterMapProducer());
afterBeanDiscovery.addBean(new RequestParameterMapProducer());
afterBeanDiscovery.addBean(new RequestParameterValuesMapProducer());
afterBeanDiscovery.addBean(new ApplicationMapProducer(beanManager));
afterBeanDiscovery.addBean(new CompositeComponentProducer(beanManager));
afterBeanDiscovery.addBean(new ComponentProducer(beanManager));
afterBeanDiscovery.addBean(new FlashProducer(beanManager));
afterBeanDiscovery.addBean(new FlowProducer(beanManager));
afterBeanDiscovery.addBean(new FlowMapProducer(beanManager));
afterBeanDiscovery.addBean(new HeaderMapProducer(beanManager));
afterBeanDiscovery.addBean(new HeaderValuesMapProducer(beanManager));
afterBeanDiscovery.addBean(new InitParameterMapProducer(beanManager));
afterBeanDiscovery.addBean(new RequestParameterMapProducer(beanManager));
afterBeanDiscovery.addBean(new RequestParameterValuesMapProducer(beanManager));
afterBeanDiscovery.addBean(new RequestProducer());
afterBeanDiscovery.addBean(new RequestMapProducer());
afterBeanDiscovery.addBean(new ResourceHandlerProducer());
afterBeanDiscovery.addBean(new ExternalContextProducer());
afterBeanDiscovery.addBean(new FacesContextProducer());
afterBeanDiscovery.addBean(new RequestCookieMapProducer());
afterBeanDiscovery.addBean(new RequestMapProducer(beanManager));
afterBeanDiscovery.addBean(new ResourceHandlerProducer(beanManager));
afterBeanDiscovery.addBean(new ExternalContextProducer(beanManager));
afterBeanDiscovery.addBean(new FacesContextProducer(beanManager));
afterBeanDiscovery.addBean(new RequestCookieMapProducer(beanManager));
afterBeanDiscovery.addBean(new SessionProducer());
afterBeanDiscovery.addBean(new SessionMapProducer());
afterBeanDiscovery.addBean(new ViewMapProducer());
afterBeanDiscovery.addBean(new ViewProducer());
afterBeanDiscovery.addBean(new DataModelClassesMapProducer());
afterBeanDiscovery.addBean(new SessionMapProducer(beanManager));
afterBeanDiscovery.addBean(new ViewMapProducer(beanManager));
afterBeanDiscovery.addBean(new ViewProducer(beanManager));
afterBeanDiscovery.addBean(new DataModelClassesMapProducer(beanManager));

for (Type type : managedPropertyTargetTypes) {
afterBeanDiscovery.addBean(new ManagedPropertyProducer(type, beanManager));
Expand Down
15 changes: 13 additions & 2 deletions impl/src/main/java/com/sun/faces/cdi/CdiProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.enterprise.inject.spi.PassivationCapable;
import jakarta.faces.context.FacesContext;
Expand All @@ -49,8 +50,7 @@ abstract class CdiProducer<T> implements Bean<T>, PassivationCapable, Serializab

private String id = this.getClass().getName();
private String name;
// for synthetic beans, the beanClass defaults to the extension that registers them
private final Class<?> beanClass = CdiExtension.class;
private Class<?> beanClass = Object.class;
private Set<Type> types = singleton(Object.class);
private Set<Annotation> qualifiers = unmodifiableSet(asSet(new DefaultAnnotationLiteral(), new AnyAnnotationLiteral()));
private Class<? extends Annotation> scope = Dependent.class;
Expand Down Expand Up @@ -165,8 +165,19 @@ protected CdiProducer<T> create(Function<CreationalContext<T>, T> create) {
return this;
}

protected CdiProducer<T> beanClass(BeanManager beanManager, Class<?> beanClass) {
if (CdiUtils.isWeld(beanManager)) {
this.beanClass = CdiExtension.class; // See #5457 and #5157
} else {
this.beanClass = beanClass;
}

return this;
}

protected CdiProducer<T> types(Type... types) {
this.types = asSet(types);
this.types.add(getClass()); // Add producer class as well so it can at least be filtered from BeanManager#getBeans().
return this;
}

Expand Down
7 changes: 7 additions & 0 deletions impl/src/main/java/com/sun/faces/cdi/CdiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,11 @@ public static <S extends Annotation> boolean isScopeActive(Class<S> scope) {
}
}

/**
* Returns true if Weld is used as CDI impl.
*/
public static boolean isWeld(BeanManager beanManager) {
return beanManager.getClass().getPackageName().startsWith("org.jboss.weld.");
}

}
Loading

0 comments on commit a019325

Please sign in to comment.