6 Replies Latest reply on May 14, 2007 3:14 PM by Vladimir Ralev

    @Begin issue. Cannot make it work how we need

    Mihai Anescu Newbie

      Hi,

      So, I have a generated Seam app, and we have placed a combo box and a button on top, near the "login" part (inside the loginout.xhtml file).
      The button calles a method, which has the @Begin annotation.
      After I login, I choose a value from the drop down and press the Change button. This will place some objects on the Conversation context.
      i also removed the propagation="none" from the s:link elements, so now i can move around with the setted values. But if I change the value for the second time I get an exception about calling begin from inside a conversation, with hint that I should use (join=true).

      So, here is what needs to work, and what is happening:
      I need to allow the objects that are placed on context to exist in 2 different conversations, that is, if the user logs in, and sets the values from the combo to X & Y, and then opens a likn in another tab/browser, having the same session, he should be able to select from the combo a different option and work in both browsers concurently, with different values placed on the conversation context.

      But, this is what I get:
      1) If I place @Begin on the method that is called from the interface when changing the value, when I change the combo value from either of the windows I get an error, with the above hint.
      2) If I use @Begin(join=true), then both windows will use the same conversation, that is, if I change from the combo in window 1 and then navigate somewhere else in window 2, the values from the conversation context will have the same values as those set in window 1
      3) If I use for example this code, then it's like @Begin is not called:

      //method called to change the value.
       @End
       public void changeSelected()
       {
       doStuff();
       }
      
      
      //method called from first one.
       @Begin
       public void doStuff()
       {
       //...
       }

      4) The same if i use this to close the existing conversation and start a new one:
      //method called to change the value.
       @End
       @Begin
       public void changeSelected()
       {
       doStuff();
       }
      
      
      //method called from first one.
       public void doStuff()
       {
       //...
       }


      Am I missing something here? How do I end the conversation only when I want to change the value???

        • 1. Re: @Begin issue. Cannot make it work how we need
          Andy Gibson Novice

          Why not just swap object X for object Y when you make the selection, and outject the value as a conversational context variable, assuming they are meant to be sharing the same context variable?

          The other option (and I'm not sure whether this will work, or how well it will work), is to put conversation propagation on the button used to make the selection.

          End the conversation on the button, and start a new conversation on the method.

          <s:button propagation="end" action="#{MyBean.makeChange}" value="change" />
          


          and annotate the method makeChange with @Begin.

          I'm not sure how well it will work since I don't know whether the end conversation is taken into account before the @Begin is reached.


          • 2. Re: @Begin issue. Cannot make it work how we need
            Mihai Anescu Newbie

            Hi,

            tried your suggestion, it's the same thing. Apparently the propagation="end" is not used at all. I mean I have the same errors as before, see here:

            Caused by: javax.faces.el.EvaluationException: /layout/loginout.xhtml @17,133 action="#{accountHubSelector.changeSelected}": java.lang.IllegalStateException: begin method invoked from a long running conversation, try using @Begin(join=true) on method: changeSelected
             at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
             at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
             ... 43 more


            What do you mean by swapping X with Y? I am doing this, but in the method that is invoked from the change button, and I am outjecting 2 objects, based on the selection in the select box. But the problem is that the method has the @Begin annotation because if we open a second browser we would need to have different context in those browsers. If I use @Begin(join=true) for example it works but both browser share the same context!

            • 3. Re: @Begin issue. Cannot make it work how we need
              Magnus Sandberg Novice

              I have also had issues like this and what I actually would like to suggest is that Seam adds yet another Scope a Window-Scope.

              This Scope should be connected to a Window and should be started/forked with each Window. It should not be @Ended like a Conversation but work more like the Session Scope.

              • 4. Re: @Begin issue. Cannot make it work how we need
                Vladimir Ralev Newbie

                Basically you need to clone the current conversation on @Begin, right?

                • 5. Re: @Begin issue. Cannot make it work how we need
                  Mihai Anescu Newbie

                   

                  "vladimir.ralev@jboss.com" wrote:
                  Basically you need to clone the current conversation on @Begin, right?


                  I would need to clone the conversation on @Begin, in a new Window. That would be the correct answer.
                  So, if I use one window keep the context, and when I shift + left click and open a new window I would need a brand new context in the new window (so that the 2 windows use the same session but different conversations, I can place in each conversation a different instance of object XYZ).

                  • 6. Re: @Begin issue. Cannot make it work how we need
                    Vladimir Ralev Newbie

                    I think I understand now. I think you should stick with @Begin(join=true), but be careful how you launch the second browser/tab. How do you do this now? You must not pass the conversation ID in the second tab, if you do, the windows will share the same conversation.