Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The module myfaces-extcdi-bundle-alternative-configuration bundles all alternative configs provided by CODI in an all-in-one JAR file.
Use the single config modules or the all-in-one bundle but not both.

Providing other alternative implementations

Sometimes it's required to activate and/or use other implementations provided by CODI or a custom implementation.
With OWB it's pretty simple - just annotate the class with @Alternative, implement the same interfaces as the original class (btw. extend from the same abstract class) and activate the implementation in the beans.xml config of CDI. As an alternative approach you can use the @Specializes annotation of CDI.

With Weld it's a bit more difficult. If the @Alternative approach doesn't work, you have to do it manually via a CDI extension.

Code Block
java
java
titleWorkaround for alternative implementations in combination with Weld

public class VetoExtension implements Extension
{
    protected void vetoDefaultImplementations(@Observes ProcessAnnotatedType<Object> processAnnotatedType)
    {
        Class beanClass = processAnnotatedType.getAnnotatedType().getJavaClass();
        if(WindowHandler.class.isAssignableFrom(beanClass) &&
                !AlternativeWindowHandler.class.isAssignableFrom(beanClass))
        {
            processAnnotatedType.veto();
        }
    }
}

public class AlternativeWindowHandler extends ServerSideWindowHandler
{
    private static final long serialVersionUID = 6089519101832237681L;
}

As with every CDI extension you have to activate the VetoExtension in META-INF/services/javax.enterprise.inject.spi.Extension