3 Replies Latest reply on Feb 8, 2011 11:19 AM by Monkey Den

    Injecting a component

    Yurien López Newbie
      Hello, i am using JEE5 (JSF,Seam,EJB3),and i am trying to inject a component without having to specify it´s @Name,for example:

      I have an Entity Bean Called:TnDosis and then for injecting it i have to put an @name to the entity:
      @Name("dosis")
      TnDosis

      @In(value="dosis")
      private TnDosis dosis;

      I need help....Thanks
        • 1. Re: Injecting a component
          Monkey Den Master

          Entity beans cannot intrinsically be Seam components.  You'll have to outject it to some scope (SESSION, CONVERSATION, APPLICATION, etc.) first.  That is to say, you must first have @Out somewhere. 


          @Out(scope=CONVERSATION)
          private TnDosis dosis;
          



          ...then @In will work.  Or, you could also create a subclass of EntityHome, to manage it's lifecycle:


          @Name("TnDosisHome")
          public class TnDosisHome extends EntityHome<TnDosis>{
              ...
          }
          


          ...and inject that instead.  If you're not already aware, EntityHome is used for entity CRUD operations and EntityQuery is used for entity searches.

          • 2. Re: Injecting a component
            Yurien López Newbie

            ok,thank you very much my friend, i did the same thing you told me an it works, but now i am proving to inject another entity bean,but in this case without put it an @name,like i do with the Entity Manager. Ex:


            @In
            private EntityManager entityManager;


            @In
            private TnDosis tnDosis;


            I tried this, and it threw an error.


            Apologize me for the inconvenience..Thanks a lot....

            • 3. Re: Injecting a component
              Monkey Den Master

              I guess I should have asked this straight away but what is it exactly that you're trying to do?  Do you have a Seam component which has already created that TnDosis for you?


              @In private TnDosis tnDosis; 
              


              What that code says to Seam is, I require an instance of TnDosis which can be found under the name 'tnDosis'.  Go find it in any scope for me.  Seam assumes you know what you're talking about so, off it goes.  It doesn't find it and tells you in the best way it knows how...an exception.  It cannot magically create it for you because it can only do that with Seam components and @Entity beans cannot be Seam components.