5 Replies Latest reply on Jun 6, 2007 6:36 PM by Hung Tang

    Injection and relation between components

    Ricardo Memoria Novice

      Hi all,

      I'm using JBOSS 4.0.5 and SEAM 1.2.1

      I don't know if it's a bug or my (wrong) way of using components.

      I have a long running conversation and a java bean component declared like this:

      @Name("drugOrderHome")
      public class DrugOrderHome extends EntityHome<DrugOrder>{
       private static final long serialVersionUID = 2666375478687085792L;
      
       @In(create=true)
       private SourceConsumptionHome sourceConsumptionHome;


      this entityHome component remains in memory until the end of the conversation. And there are several requests during the conversation .

      PROBLEM: The state of the component injected (sourceConsumptionHome) is lost between every request inside the long running conversation, while the DrugOrderHome component remains intact.

      Is this a feature or a bug? Is there a way of preserving the state of the injected component?

      Regards,
      Ricardo Memória


        • 1. Re: Injection and relation between components
          Hung Tang Apprentice

          Is SourceConsumptionHome a regular javabean? If you haven't already, try adding a Scope=Conversation to the class.

          EntityHome objects are, by default, conversation-scoped so they will participate through the entire lifecycle of a conversation, but regular javabean components are event-scoped.

          • 2. Re: Injection and relation between components
            Hung Tang Apprentice

            As well, if you SourceConsumptionHome is in fact already conversation-scoped, you may want to try adding @Out to make sure the changes are outjected.

            • 3. Re: Injection and relation between components
              Gavin King Master

               

              "hstang" wrote:
              As well, if you SourceConsumptionHome is in fact already conversation-scoped, you may want to try adding @Out to make sure the changes are outjected.


              This is not necessary.

              Just make sure that the sourceConsumptionHome component is conversation scoped.

              • 4. Re: Injection and relation between components
                Ricardo Memoria Novice

                Yes... It started working after I've included the component in conversation scope:

                @Name("drugOrderHome")
                public class DrugOrderHome extends EntityHome<DrugOrder>{
                 private static final long serialVersionUID = 2666375478687085792L;
                
                 @In(create=true)
                 private SourceConsumptionHome sourceConsumptionHome;


                @Name("sourceConsumptionHome")
                @Scope(ScopeType.CONVERSATION)
                public class SourceConsumptionHome {


                OK... it's working nicely and perfectly. But to finish this topic, 2 more questions to the gurus:

                1 - Why the first component doesn't require a @Scope(ScopeType.CONVERSATION) declaration like the second ? (the first component remains in memory up to the end of the conversation);

                2 - I tryed before @In(create=true, scope=ScopeType.CONVERSATION) to inject the second component, but it wasn't created in a conversation scope. What does this declaration mean?

                Thanks,
                Ricardo

                • 5. Re: Injection and relation between components
                  Hung Tang Apprentice

                  Hello,

                  "rmemoria" wrote:
                  1 - Why the first component doesn't require a @Scope(ScopeType.CONVERSATION) declaration like the second ? (the first component remains in memory up to the end of the conversation);

                  You extended EntityHome, which I assume is part of the framework package in Seam, which is setup as conversation-scoped by default.

                  "rmemoria" wrote:

                  2 - I tryed before @In(create=true, scope=ScopeType.CONVERSATION) to inject the second component, but it wasn't created in a conversation scope. What does this declaration mean?

                  I'm guessing it means to inject a context variable from the conversation scope. If it's not found, create it.