8 Replies Latest reply on Apr 6, 2006 9:45 AM by gavin.king

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

    superfis

      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
          mirko27

          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
            superfis

             

            "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
              superfis

              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

                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
                  superfis

                  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

                    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
                      superfis

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

                      • 8. Re: Seam remoting + long-running conversation. Is it possibl
                        gavin.king

                        coo! No problem.