I have added a PhaseListener
to faces-config.xml
:
<lifecycle>
<phase-listener>com.project.NotificationListener</phase-listener>
</lifecycle>
The class seems to be otherwise correct as it is pretty simple.
public class NotificationListener implements PhaseListener {
@Inject
private MyCDIStuff stuff;
@Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
@Override
public void beforePhase(PhaseEvent event) {
this.stuff.doStuff();
}
}
The 'beforePhase' method gets called correctly, however the MyCDIStuff object is null. I tried using annotation @Singleton
for the class which most likely was incorrect, and it didn't make the injection work either.
Is there a way to inject CDI managed beans in the PhaseListener
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…