4 Replies Latest reply on Jul 20, 2008 1:22 AM by Francisco Jose Peredo Noguez

    How to access a seam component from a Phase Listener?

    Ken Clark Newbie

      I assume I can't use injection in a Phase Listener, so how would I go about accessing a named Seam component (which will be in the Page scope)? 


      Correspondingly, how can I make sure it is stored in the next page scope?

      Thanks,
      ken

        • 1. Re: How to access a seam component from a Phase Listener?
          Pete Muir Master

          Use Component.getInstance() but only after the restore phase.

          • 2. Re: How to access a seam component from a Phase Listener?
            Ken Clark Newbie

            Excellent!  Thank you.


            It seems like just retrieving the object this way does not in itself put the object into the Page scope, so I have tried this:




                Contexts.getPageContext().set("usercfg", userConfig);
            



            But it does not seem to be doing what I want it to do.  Is there something incorrect in this code?


            I am trying to force a value into the page scope from page to page for downstream use, but as soon as I leave the page where I am directly Outjecting the value, it is lost.  I was hoping I could bridge that gap using a PhaseListener.


            The component class is basically:


            @Name("usercfg")
            @Scope(ScopeType.PAGE)
            @AutoCreate
            public class UserConfig implements Serializable
            {
            // ...
            }



            Note:  I am still trying to find a solution to the problem I originally posted at: wiki://32052.


            Thanks,
            ken



            • 3. Re: How to access a seam component from a Phase Listener?
              Ken Clark Newbie

              I understand things a little better now and realize that what I am trying to do fundamentally will not work using the PAGE scope, because PAGE does not survive through a redirect.  So the first redirect I hit ends the series I need to continue unbroken.


              I have tried a little bit with conversation, since (so I thought) there would always be a conversation between two pages -- even through a redirect -- either a long-running or temp conversation.  This works much better, but the first time I pass through a

              s:link with propagation="none"

              I lose the values.


              So I am going to research Seam scopes more to see if I can find a way past this wall.  Any suggestions are appreciated.


              Thanks,
              ken


              • 4. Re: How to access a seam component from a Phase Listener?
                Francisco Jose Peredo Noguez Master

                That is because <s:link with propagation="none"> is precisely for losing the values. (propagation="none" means no propagation of conversation (and therefore no propagation of values inside the conversation))


                I find it a little odd (I hope that you take no offense) that you think it may be easier to modify the internal workings of Seam. and create new ScopeType than trying to understand current Seam ScopeTypes (and see if they help you do what you need)