1 Reply Latest reply on Jun 7, 2008 1:23 AM by Norman Richards

    Scopes and Components....Tough Question?

    V. E. Newbie

      I am new with Seam, I like it.  I have a question though..


      Can I can call methods on a component scope that's higher than the component that I am making the call from.


      For example, given a session bean


      @Name("cart")
      @Scope(ScopeType.SESSION)
      public class Cart {
         public void addItem(Product product) {...}
      }
      



      Can I call this bean from a conversation component?


      @Name("productCustomizer")
      @Scope(ScopeType.CONVERSATION)
      public class ProductCustomizer {
         @In
         private Cart cart;
        
         @In(name="productBeingCustomized")  //this is a product object I mapped to the conversation scope
         private Product product;
      
         public void endConfigurationAndPutInCart() {
            cart.addItem(product);
         }
      }
      



      Is this an ok thing to do?  How would things change given that there are transactions?  Is there a rule of thumb that I can remember when doing stuff like this? 


      Thanks.


      I appreciate your help.

        • 1. Re: Scopes and Components....Tough Question?
          Norman Richards Expert

          Yes, calling cart here is just fine for Seam.  You could inject the other direction too (conversation component into session component) if you wanted, but I think the way you did it here is generally the more natural way.  Another option is to use extended EL and simply make the end action #{cart.addItem(productBeingCustomized)} and avoid any coupling at all.  There are no hard rules.  Just do whatever seems to yield the most natural code.


          Transactions don't change at all here if you are using seam managed transactions.  (assuming you don't need the cart to execute in a separate tx)