1 Reply Latest reply on Nov 18, 2010 11:53 AM by Christoph Kraus

    how to inject an EntityHome component into an EntityQuery component in a conversation scope

    Andrew Geery Newbie
      Seam 2.2.0GA

      I have a list of collections/groups.  Each collection has a list of assets/items in it.

      I have a CollectionHome class which extends EntityHome.  The scope for this class is CONVERSATION.  The class has a method annotated with @Begin to start the conversation.

      I have an AssetQuery class which extends EntityQuery.  The scope for this class is also CONVERSATION.  There is a variable in this class called collectionHome with an @In annotation which is supposed to inject the CollectionHome object in the same conversation.  The CollectionHome object is injected so a query can be written to get the list of assets in the currently selected collection.

      Here's the basic code for this:

      @Name("collectionHome")
      @Scope(ScopeType.CONVERSATION)
      public class CollectionHome extends EntityHome<Collection> {

           private Integer id;

           @Override
           public Object getId() {
                if (id == null) {
                     return super.getId();
                } else {
                     return id;
                }
           }

           @Begin(join = true)
           public void beginContent() { }

           @End
           public void endContent() { }

      ...

      }     


      @Name("assetList")
      @Scope(ScopeType.CONVERSATION)
      public class AssetQuery extends EntityQuery<Asset> {

           @In(required = true)
           private CollectionHome collectionHome;

      ...
           
      }


      Using the debugger, I have verified that the CollectionHome class is indeed getting created first and the method annotated with @Begin is getting called to start the conversation.  However, when the AssetQuery class is created, an exception is thrown because the injected CollectionHome object is null.

      I know that I can set create=true on the @In annotation, but that really isn't what I want to do.  I want the AssetQuery to reference the same CollectionHome component in the conversation that has already been created.

      The only thing I can think of is that the two components are, in fact, in different conversations.  What do I have to do to get them in the same conversation?  Do I need to inject AssetQuery into CollectionHome because the conversation started in CollectionHome or do I also need to have a @Begin(join = true) annotation in the AssetQuery class?

      Using the debugger to examine the context, is there an easy way to determine the conversation a component is in?

      Thanks
      Andrew