10 Replies Latest reply on Oct 24, 2007 11:42 AM by Pete Muir

    nested conversation question

    valbosoft Newbie

      Hello,

      when I start a nested conversation, I set a few page parameters in the page.xml file. These parameters set values in a Home class. What I wanted is that this Home class only exists in the child conversation, but it seems that it's inserted in the parent conversation.
      I guess it can be resolved by giving the Home a PAGE scope, but I was wondering if there's another way, in case I wanted to keep the Home in the nested conversation, for example..

      Regards, Bo

        • 1. Re: nested conversation question
          Jacob Orshalick Apprentice

          Is Seam instantiating your Home instance? If so, I would recommend looking at the timing of when Home is instantiated. You could do this by adding a method annotated with @Create and printing out a message. Home must be inserted into the conversation context AFTER the nested conversation is started (the event org.jboss.seam.beginConversation can be observed to determine when your conversation begins). Hope that helps.

          • 2. Re: nested conversation question
            Hung Tang Apprentice

            I haven't really used this myself, but Seam has this annotation @PerNestedConversation--it may or may not do what you want.


            http://docs.jboss.com/seam/2.0.0.CR2/reference/en/html/conversations.html#d0e4653



            /**
            * Limit the scope of a CONVERSATION-scoped component
            * to just the parent conversation in which it was
            * instantiated. The component instance will not be
            * visible to nested child conversations, which will
            * get their own instance.
            *
            * Warning: this is ill-defined, since it implies that
            * a component will be visible for some part of a
            * request cycle, and invisible after that. It is not
            * recommended that applications use this feature!


            • 3. Re: nested conversation question
              valbosoft Newbie

              Thanks guys.

              hstang: I guess I forgot to mention I use Seam 1.2.1...

              Jacob: the parent of my Home, EntityHome, apparently already defines the @Create annotation, I get a duplicate error when I use that for my own method.

              The Page scope doesn't work either: the page parameter I use to initiate the id of the Home is loaded the first time, but the second time the parameter of the first time is used (although setId(Object id) IS being called every time, but always with the parameter I used the first time). This is useless, because I need the Home component's instance to be different every time it's being called..

              Regards, Bo

              • 4. Re: nested conversation question
                Jacob Orshalick Apprentice

                 

                "valbosoft" wrote:
                the parent of my Home, EntityHome, apparently already defines the @Create annotation, I get a duplicate error when I use that for my own method.


                Ok, then you could observe the event org.jboss.seam.postCreate. where is the name of your component to determine creation time.

                • 5. Re: nested conversation question
                  Jacob Orshalick Apprentice

                  should read "event org.jboss.seam.postCreate.<name>"

                  • 6. Re: nested conversation question
                    Paul Pantages Novice

                    Hello valbsoft,

                    How do you start the nested conversation?

                    I ran into something similar a while ago, when I used something like:

                    @Begin(nested=true)
                    public String edit()

                    to start my conversation. The bean was created in the parent conversation.
                    The nested conversation was only started when edit() returned a non null outcome.

                    Since my edit method was called through s:link, I removed the
                    @Begin(nested=true)

                    and added
                    "propagation=nest"
                    to the s:link.

                    This caused the conversation to begin before edit() was called; I printed my conversationId from my @Create and @Destroy methods to verify that the object created/destroyed solely in the nested conversation.

                    The only issue I found is that, now, if my edit() returns null, the conversation is still started, and I need to manually call conversation.instance().end()/pop() to clean it up.

                    PdP

                    • 7. Re: nested conversation question
                      valbosoft Newbie

                      Thanks PdP, looks like it's got to do with it.

                      Jacob,

                      a strange thing is happening:
                      the Home component is already being created when I load the page before (Vivienda.xhtml), where I put the link to the next page, which is supposed to start the nested conversation. I use the following construction:

                      <s:link propagation="nest" ....><f:param ..../></s:link>

                      On this page, I have no reference whatsoever to the Home component.
                      The page.xml file for the NEXT page (presentacionEdit.xhtml, which starts the nested conversation) *does* contain references to the Home component.

                      Now, the Home component doesn't get constructed during the loading of Vivienda.xhtml when I take away the references to the Home in the presentacionEdit.page.xml file (!!)
                      It seems like Seam anticipates on the load to the next page, and loads the corresponding page.xml file, which initiates the Home component.

                      My intention was to initiate the Home component with a page parameter every time I clic on the <s:link> link...

                      Regards,
                      Bo

                      • 8. Re: nested conversation question
                        Jacob Orshalick Apprentice

                        The following post discusses this:

                        http://www.jboss.com/index.html?module=bb&op=viewtopic&t=119611

                        Knowing this, you may have to consider a slightly different approach to ensure that the instance is created after nesting. Do you have to send the parameters through pages.xml? Could you simply outject the ID to the conversation context making it available to a factory method? Or you could set the pages.xml parameter into the component responsible for creating your Home instance. There are a number of other approaches you could consider as well. Hope that helps.

                        • 9. Re: nested conversation question
                          valbosoft Newbie

                          Hello,

                          good tip, the one of observing the create event, it really helped.

                          Thanks for the replies!

                          I'll do the implementation with @RequestParameters, a quick test shows that works well.

                          Regards, Bo

                          • 10. Re: nested conversation question
                            Pete Muir Master

                             

                            "valbosoft" wrote:
                            It seems like Seam anticipates on the load to the next page, and loads the corresponding page.xml file, which initiates the Home component.


                            Yes.