1 Reply Latest reply on May 23, 2006 11:31 AM by Pete Muir

    Setting properties on injected bean

    Ido Tamir Newbie

      Hello everybody,

      I am now successfully using seam with pageflows for wizards :-) very nice.
      I would like to be able to parameterize @Factory or what @DataModel returns from my bean dependent on the page/pageflow etc.. the bean was instantiated in.

      What I am doing now is to have a bean that models the flow that is injected with one or more editors that display selectable items.
      Depending on the Class the ItemEditor is injected into I would like to set members in the ItemEditor that influence the outcome of @DataModel.

      Trying something like below results in (I tried to follow the debug output):
      INFO [ConversationInterceptor] no long-running conversation for @Conversational bean: itemEditor
      then the criteria seem to be set
      and afterwards the long running conversation starts, but without criteria.

      thank you very much
      ido

      @Conversational
      class PageFlowBean ...{
      
       @In (create=true)
       private ItemEditor itemEditor;
      
       @Begin(join=false,pageflow="editFlow1")
       public void createItem() {
       itemEditor.setCriteria("car");
       }
      }
      
      @Name("itemEditor")
      @Scope(ScopeType.CONVERSATION)
      @Stateful
      class ItemEditorBean implements ItemEditor {
       @PersistenceContext(type=PersistenceContextType.EXTENDED)
       private EntityManager em;
      
       String criteria;
       public void setCriteria(String criteria){
       this.criteria = criteria;
       }
      
       @DataModel(scope=ScopeType.PAGE)
       private List<Item> itemList;
       @DataModelSelection(value="itemList")
       private Item item;
      
       ......
      
       @SuppressWarnings("unchecked")
       @Factory(value="itemList")
       public void loadItems{
       if( criteria != null){
       itemList = em.createQuery("from Item as item where item = '"+ criteria + "'" );
       }
       }
      
       @Create
       public void initialize() {
      
      }
      


        • 1. Re: Setting properties on injected bean
          Pete Muir Master

          To me it doesn't look like you've started a conversation on itemEditor - hence the error message.

          It seems unlikely that a long running conversation is starting in itemEditor without any method @Begin. You can check if a new conversation is acutally created on the debug page.

          If you inject a stateless bean into a conversational bean then the stateless bean will exist for the lifespan of the conversational bean. I think something similaris happening here (but with a stateful bean that isn't long-running)?

          My solution would be to add @Begin(join=true) to the @Create method of itemEditorBean. This will cause the itemEditor to join the existing conversation AND will be ended at the next @End annotation (in either bean).

          HTH