4 Replies Latest reply on Apr 23, 2007 4:06 PM by Vineet Manohar

    Conversation binding workaround

    Vineet Manohar Newbie

      Hi,

      Currently I have a seam component "numberGuess" with Conversation.SCOPE. It has a binding that I want to use on the view page directly, but can't because of seam limitation.

      @Name("numberGuess")
      @Scope(ScopeType.CONVERSATION)
      public class NumberGuess implements Serializable {
       private UIInput input;
      }


      My view is as follows:
      <h:inputText binding="#{numberGuess.input}"/>


      I realize that conversation scoped components cannot be accessed through "binding" from the view, as discussed in the following posts:
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=97544
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=99270
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=97182

      As a workaround the posts suggest that "Just do you bindings on an event scoped object and inject that object in."

      I am new to seam and would appreciate if someone could explain a bit more specifically how to accomplish the above. Do I need to create a new seam component with EVENT scope?

      Thanks in advance!

        • 1. Re: Conversation binding workaround
          Pete Muir Master

          Exactly.

          @Name("binding")
          @Scope(EVENT)
          public class Binding {
          // Do your binding here
          }


          @Name("numberGuess")
          @Scope(ScopeType.CONVERSATION)
          public class NumberGuess implements Serializable {
          
           @In Binding binding
          
           // Do work on the binding in your method
          
          }


          • 2. Re: Conversation binding workaround
            Vineet Manohar Newbie

            Thanks for you reply, that was very helpful.

            So suppose I created a seam component called "binding" with EVENT scope as you have suggested, how can I initialize it? I want to set the value of this component from my Conversation component "numberGuess".

            Can I @Out-ject the value from Conversation to Event scope?

            • 3. Re: Conversation binding workaround
              Pete Muir Master

              Yes

              @Name("numberGuess")
              @Scope(ScopeType.CONVERSATION)
              public class NumberGuess implements Serializable {
              
               @In(create=true) @Out Binding binding;
              
               @Create
               public void createBinding() {
               binding.setFoo("bar");
               }
              
               // Do work on the binding in your method
              
              }


              • 4. Re: Conversation binding workaround
                Vineet Manohar Newbie

                Thanks again for the reply. I tried exactly what you said and ran into a problem.

                binding="#{binding.myBean.myComponent}": Target Unreachable, 'myBean' returned null


                I debugged and found that my @Create method in NumberGuess was not called yet. Therefore the @Out-jection did not occur yet. It seems that when I access the numberGuess.xhtml page, the bindings are first resolved on the xhtml page first, and then the conversation is started which and that is when my @Create method is called.

                I start the conversation by typing the /numberGuess.xhtml url in the browser. I have the following entry in my pages.xml
                <page view-id="/numberGuess.xhtml">
                 <begin-conversation join="true" pageflow="numberGuess"/>
                 </page>


                How can I first start my conversation and then redirect to the view? How can I start a conversation by typing a URL but using start-state, instead of start-page?