Before JSF 2.2, PhaseListener
s are not registered as CDI injection targets. Using @Inject
(and @EJB
) has effectively no effect in PhaseListener
s. You'd need to manually grab the CDI managed beans by programmatically evaluating an EL expression referencing the @Named
's (implicit) name, or as last resort via JNDI and BeanManager
which is quite clumsy.
So, if you can't upgrade to JSF 2.2 (which should be compatible with any JSF 2.0/2.1 and Servlet 3.0 compatible web application), then your best bet is programmatically evaluating an EL expression referencing the @Named
name. Assuming that you've a
@Named("stuff")
public class MyCDIStuff {}
then this should do:
FacesContext context = event.getFacesContext();
MyCDIStuff stuff = context.getApplication().evaluateExpressionGet(context, "#{stuff}", MyCDIStuff.class);
// ...