2 Replies Latest reply on May 22, 2006 12:43 PM by Dan Liu

    the bookmarded url has conversationId when using redirect in

    Dan Liu Apprentice

      I've been having problem with bookmark pages for a couple of days and hope to get someone's help here.

      let me describe my scenario in short. Say I can list many shops and each shop can sell many items. Each shop has got its own id, so they can be accessed by a bookmakable url (e.g. http://abcd.com/shop.seam?id=22), or through our search utilities.

      When shop.seam is being accessed, I've defined an action method in pages.xml and this method outject a list of items that shop sells. In shop.xhtml, all the items are showed with a checkbox beside. Users can tick the items they want, and finally click on "Buy now" to buy their interested items.

      By looking at seam blog example, here are 2 ways to implement this function I've tried so far:
      1. Define a stateful bean. Here is what this bean looks like:

      @Stateful
      @Name("shopAction")
      public class ShopAction ...
      {
       @RequestParameter
       String id;
      
       @In(scope=Conversation)
       @Out(scope=Conversation)
       List items;
      
       public void showShop(){
       items=getShopItems(id);
       }
      
       public String buyNow(){
       List selectedItem=getSelected(items);
       ....
       }
      }
      


      Using stateful bean pretty much solved my problem but with 2 pitfalls:
      1) when shop.seam is redirected from my search bean, the url would have conversationId=xx included (e.g. http://abcd.com/shop.seam?id=22&converstationId=2). this is not right since user doesn't wanna bookmark the conversation ID.
      2) Each time when user browses a shop's items, there will be a new conversation created. This is not performant enough because users quite often browse a lot of shops before buying anything.

      2. My second approach is to use stateless bean. This is how seam blog example implemented the bookmark function. With this approach, I can't find a way to pass items between showShop() and buyNow() since Stateless bean can't manipulate conversational stuffs.

      Has anyone experienced this problem before?

        • 1. Re: the bookmarded url has conversationId when using redirec
          Norman Richards Master

          The conversation id isn't a huge problem. If the conversation doesn't exist, a new one is created. It is really just an issue of whether or not you find the conversationId distracting. (well, in theory it is a problem for us because the ids are non-random and conversation "17" might actually exist for another user - we should make the conversation ids long random numbers like an HTTP session id)

          That being said, you can control the conversation id propagation using the s:conversationPropagation tag. (use "none" to make sure the links don't preserve the conversation) However, if you want to abandon the conversation, I wonder if you really wanted the conversation in the first place? Why not simply not create the conversation in the first place?

          • 2. Re: the bookmarded url has conversationId when using redirec
            Dan Liu Apprentice

            Thanks for reply.

            Without creating a converstaion, how can I pass the objects between invocations? Here is what I've tried for my second approach by having 2 seperate beans:

            @Stateless
            @Name("shopAction")
            public class ShopAction ...
            {
             @RequestParameter
             String id;
            
             @Out(scope=Conversation)
             List items;
            
             public void showShop(){
             items=getShopItems(id);
             }
            
            }
            
            @Stateful
            @Name("bookAction")
            public class ShopAction ...
            {
            
             @In(scope=Conversation)
             List items;
            
             @Begin
             public String buyNow(){
             List selectedItem=getSelected(items);
             ....
             }
            }
            


            The shopAction is unable to outject items because it's a stateless bean. When bookAction.buyNow() is invoked, it needs to inject items from previous operation.

            In summary, I need a way to pass objects from stateless bean to a conversational stateful bean.

            Any idea?