8 Replies Latest reply on Apr 6, 2006 9:45 AM by Gavin King

    Seam remoting + long-running conversation. Is it possible?

    slawek t Novice

      Hi,

      I tried to entangle @WebRemote method (SFSB) in long-running conversation by @Conversational annotation, but it didn't work. I'd been notised that there is no long-running conversation for @Conversational bean, and started new conversation.

      Is it possible to keep remotely invoked methods in long-running conversation?


      Slawek

        • 1. Re: Seam remoting + long-running conversation. Is it possibl
          Mirko Adari Novice

          It does not mark bean as long-running conversation start trigger.
          You have to start llong-ronning conversation by @Begin annotation.
          This means that no method of this bean cannot be used unless you have started long-running conversation for this bean.

          • 2. Re: Seam remoting + long-running conversation. Is it possibl
            slawek t Novice

             

            "mirko27" wrote:
            You have to start llong-ronning conversation by @Begin annotation.
            This means that no method of this bean cannot be used unless you have started long-running conversation for this bean.


            Sorry for not complete explanation. I've got fiew SFSBs with actions in long-running conversation. First of these methods has @Begin and conversation lasts until remote action invocation (marked by @WebRemote).

            this is my bean:

            @Stateful
            @Name( "selectSeat" )
            @Conversational( ifNotBegunOutcome = "ERR" )
            @Interceptors( SeamInterceptor.class )
            public class SelectSeatAction implements Serializable, SelectSeat {
            
             private static final long serialVersionUID = 1L;
            
             @PersistenceContext( type = PersistenceContextType.EXTENDED )
             private EntityManager cinemaDatabase;
            
             private Set<Seat> selectedSeats = new HashSet<Seat>( );
            
             @Out( scope = ScopeType.CONVERSATION )
             Seat seat;
            
            
             @Begin( join = true )
             public String select( String place ) {
            
             this.seat = (Seat) cinemaDatabase.createQuery( "from Seat where row || ',' || number = :place" ).setParameter(
             "place", place ).getSingleResult( );
            
             selectedSeats.add( seat );
            
             return seat.getState( ).toString( );
             }
            
             @Destroy
             @Remove
             public void destroy( ) {
            
             }
            }
            


            • 3. Re: Seam remoting + long-running conversation. Is it possibl
              slawek t Novice

              I've put wrong version, correct code is without @Begin( join = true ) line:

              @Stateful
              @Name( "selectSeat" )
              @Conversational( ifNotBegunOutcome = "ERR" )
              @Interceptors( SeamInterceptor.class )
              public class SelectSeatAction implements Serializable, SelectSeat {
              
               private static final long serialVersionUID = 1L;
              
               @PersistenceContext( type = PersistenceContextType.EXTENDED )
               private EntityManager cinemaDatabase;
              
               private Set<Seat> selectedSeats = new HashSet<Seat>( );
              
               @Out( scope = ScopeType.CONVERSATION )
               Seat seat;
              
              
               public String select( String place ) {
              
               this.seat = (Seat) cinemaDatabase.createQuery( "from Seat where row || ',' || number = :place" ).setParameter(
               "place", place ).getSingleResult( );
              
               selectedSeats.add( seat );
              
               return seat.getState( ).toString( );
               }
              
               @Destroy
               @Remove
               public void destroy( ) {
              
               }
              }
              


              • 4. Re: Seam remoting + long-running conversation. Is it possibl
                Gavin King Master

                It is possible, and the chatroom example does this. I'll let Shane give a full explanation...

                • 5. Re: Seam remoting + long-running conversation. Is it possibl
                  slawek t Novice

                  After my short investigation (based on chatroom) I know there is necessity to set up conversationId, like:

                  ...
                  SeamRemote.getContext().setConversationId(context.getConversationId());
                  ...


                  This conversationId comes with response and I can read it from context in callback javascript function. It works (I suppose) only if long-running conversation starts in remote action (like in chatroom) and first time I can read conversationId is right after first remote action invocation. What about long-running conversation beginning in different action bean? How to receive conversationId value, the remote action should be invoke with?

                  • 6. Re: Seam remoting + long-running conversation. Is it possibl
                    Gavin King Master

                    Get it from a hidden field....

                    <input id="conversationId" type="hidden" value="#{conversation.id}"/>



                    (That's assuming a facelets page, JSP might be a little bit messier.)

                    • 7. Re: Seam remoting + long-running conversation. Is it possibl
                      slawek t Novice

                      Thank you Gavin very much. It has solved my problem.