3 Replies Latest reply on Jun 9, 2009 4:23 AM by maxlamenax

    Injecting EJB in JSF Beans

      Hi all,
      I have deployed an application on JBoss 5 where my EJBs are injected into my JSF Managed Beans.

      I need to fill some comboboxes from the Constructor of the JSF Beans, however in the Constructor in the EJB injection still hasn't happened.
      Is it a bug ? any workaround ?

      public class JSFBean {
      
       ArrayList list;
      
       @EJB(mappedName = "AppEJB/local")
       private ApplicationManager ejb;
      
       public JSFBean () {
       list = ejb.populateCombo(param1);
       }
       . . . . .
      }


      The injected resource (ejb) is null in the constructor but in other methods is correctly injected.
      Thanks
      marco

        • 1. Re: Injecting EJB in JSF Beans
          jaikiran

           

          The injected resource (ejb) is null in the constructor but in other methods is correctly injected.


          The injection is guaranteed to have happened when the @PostConstruct (i guess there's some similar annotation for JSF beans) is invoked, but not when the constructor is called. So you can't rely on the injected bean in the constructor.


          • 2. Re: Injecting EJB in JSF Beans

            thank you very much. With @PostConstruct it works!

            • 3. Re: Injecting EJB in JSF Beans

              Hello,

              I am on this problem too, and in another discussion i show they speak about "@PostConstruct"...

              But at the moment i don't arrived to inject muy facade/session bean CRUD in a JSF bean ...

              Can you post a simple example, which work good with a JBoss 5.0, please ?

              With a source of a simple entity, a simple session, a simple controller, the JSF page code, and the manage bean configuration in the face-config.xml ?

              it makes somes times i try to make this run... and i need help !

              Thanks a lot in advance !