3

I'm working with a Wildfly 10 server and I'm having issues with a JSF phase listener not getting an EJB injected to it. Here is my test code that I can't seem to get to work right.

public class TestListener implements PhaseListener {
@EJB
BasicEJB bjb;

private final static Logger LOGGER = Logger.getLogger(TestListener.class.getName());

@Override
public void afterPhase(PhaseEvent arg0) {
    LOGGER.log(Level.INFO, "After Restore View event hook called.");

}

@Override
public void beforePhase(PhaseEvent arg0) {
    LOGGER.log(Level.INFO, "Before Restore View event hook called.");
    bjb.callMe(); // crash happens right here.
}

@Override
public PhaseId getPhaseId() {
    return PhaseId.RESTORE_VIEW;
}
}

If I comment out the bjb.callMe(); line, the program works like normal. With it, I get a NullPointerException. I am able to inject this EJB and use it in a @RequestScoped backing bean.

I've learned that before JSF 2.2, you couldn't inject into a Phase Listener, however, I'm on JSF 2.2.12 with this server. Whats more, I can deploy this exact code on a Glassfish4 server and it works. What am I doing wrong with Wildfly?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Psirax
  • 51
  • 7
  • As long as you're using the Java EE API and it works on Glassfish, I don't think anyone can say you're doing something "wrong" on Wildfly. If you can reproduce the problem with a _truly minimal_ example (a fresh project with a single EJB and a single PhaseListener), you might report a bug on the WildFly project. Just a suggestion. – DavidS May 13 '16 at 17:29
  • To exclude one and other, what if you use `@Inject` instead of `@EJB`? – BalusC May 14 '16 at 21:41

1 Answers1

1

Injecting an @EJB in a JSF PhaseListener on Wildfly is apparently bugged at the moment. See https://developer.jboss.org/thread/269770 for reference.

However, if I change the annotation to @Inject instead of @EJB, it works just fine. (Thanks to BalusC and the JBoss forum contributors for that suggestion)

Psirax
  • 51
  • 7