5 Replies Latest reply on Feb 12, 2009 12:14 PM by eligriv

    Problem with @In attribute with required=true but null

      Hi,


      I have a problem using a component in scope APPLICATION with @startup into a component in scope PAGE


      @Startup
      @Stateful
      @Synchronized
      @Name("applicationContextBO")
      @Scope(ScopeType.APPLICATION)
      public class ApplicationContextBO implements ApplicationContextBS {
      ...
      }




      @Scope(ScopeType.PAGE)
      @Name("itemGenerator")
      public class ItemGeneratorBO implements ItemGeneratorBS {
      
           @In(scope = ScopeType.APPLICATION, value = "applicationContextBO", required = true)
           private ApplicationContextBS applicationContextBS;
      
      ...
      
           public void populate() {
                items = applicationContextBS.getItems();
           }
      }



      I don't have an exception saying that the @in value is null, but when i call populate, i get a nullpointerexception : the 'applicationContextBS' attribute is null !


      How is it possible ? What can i do ?


      Thanks for helping. I hope I was clear enough.

        • 1. Re: Problem with @In attribute with required=true but null

          Apparently, replacing @postconstruct by @create worked. Don't ask why.

          • 2. Re: Problem with @In attribute with required=true but null
            pedrosena

            May I ask you why you are making a Application-scoped component a EJB too ?


            It sounds strange for me.


            Thanks

            • 3. Re: Problem with @In attribute with required=true but null

              I am a beginner, so it is likely that everything i do may sound strange :/


              I wanted some sort of singleton for handling all database requests related to the context entities which won't change often. It has a caching system, and offers methods to treat those entities. So i made it an Application scoped, which include some @EJB tags for my DAO ejbs.


              While i'm here, i'd like to ask something :


              My component ItemGenerator is not an EJB, right ? So do i have to make an interface out of it, like EJBs, or will it work without it ?


              Thanks, and again, sorry for my low level of english.

              • 4. Re: Problem with @In attribute with required=true but null
                pedrosena

                Hi Bob.


                Your ItemGenerator component is not an EJB, it's just a Seam Component. Like your ApplicationContextBO should be :)


                Seam components do not need to have an interface, wich, in some cases, is very interesting, if you may change the implementation at runtime.


                To make your DAOs, take a look at EntityHome and EntityQuey (for JPA) or
                HibernateEntityHome and HibernateEntityQuery


                They are a good begining for creating DAOs, even if you already have a Supertype for your DAOs, take a look at them, its very easy to adaptate it in a way that you can use the power of the EntityHome.


                Hope it helps :)


                Pedro Sena

                • 5. Re: Problem with @In attribute with required=true but null

                  My DAOs are used in some other non-seam-applications, i can't change everything :/


                  Thanks for the itemGenerator clarification.