4 Replies Latest reply on May 17, 2016 11:53 AM by Eric Parkerson

    Injecting into JSF Phase Listeners with JSF 2.2

    Eric Parkerson Newbie

      I am having trouble with an application I wrote that injects an @EJB reference into a JSF phase listener. My application was originally developed and tested using a Glassfish4 server but we have decided to attempt migration to Wildfly 10. Everything works well, except for this JSF phase listener injection.

       

      I simplified things by writing a simple JSF application that has one web page (that amounts to "Hello World"), one EJB (BasicEJB with one function, callMe(), that does nothing), and one JSF phase listener class. Here is the code for the Phase Listener.

       

      public class TestPhaseListener implements PhaseListener {

          @EJB

          BasicEJB bjb;

         

          @Override

          public void afterPhase(PhaseEvent arg0) {

              bjb.callMe(); // comment me out, and I'll run just fine. Leave me here and I'll crash on a NullPointerException.

          }

       

          @Override

          public void beforePhase(PhaseEvent arg0) { }

       

          @Override

          public PhaseId getPhaseId() {

              return PhaseId.RESTORE_VIEW;

          }

      }

       

      As the comment in the code says, if I try to call the EJB's method, I get a NullPointerException. Without it, it happily does the nothing that it was designed to do.

       

      I understand that in JSF 2.1 and before, JSF PhaseListeners do not get anything injected into them. That changed in JSF 2.2, as I understand it, and Wildfly 10 is JSF 2.2 compliant. (The JSF module file is jboss-jsf-api_2.2_spec-2.2.12.jar).

       

      I've also tried running this test on Wildfly 8.2, who's JSF module file is jboss-jsf-api_2.2_spec-2.2.8.jar, and I get the same issue. However, this simple test project runs perfectly on GlassFish4.

       

      My question is, do I have something misconfigured on my Wildfly server, or is this a bug? I'm at a loss of how to proceed here. I know I can use the JNDI lookup to get a reference to my object, but I'd prefer to be able to inject my EJB. Thoughts?