4 Replies Latest reply on Sep 20, 2006 9:27 AM by texan

    Problem outjecting a field

    taprogge

      Hi!

      I have a problem here which I have been unable to solve...
      I have here two statufel Seam session beans. One uses the DataModel and DataModelSelection mechanism to fetch some data rows. The other is used to edit an item from that list.
      What I have done is this: I added a getter for the DataModelSelection field to the ListAction bean and a method to the EditAction bean that gets the field from the list action and stores it in it's own variable which is marked for outjection:

      @Stateful
      @Scope(SESSION)
      @Name("listAction")
      public class ListActionBean implements ListAction {
      
       @DataModel
       private List<Charge> chargeList;
      
       @DataModelSelection
       private Charge chargeItem;
      
       @PersistenceContext
       private EntityManager em;
      
       @Factory
       public void getChargeList() {
      
       chargeList = (List<Charge>) em.createQuery("FROM Charge c")
       .getResultList();
       }
      
       public String refreshList() {
       getChargeList();
       return Outcome.REDISPLAY;
       }
      
       public Charge getChargeItem() {
       return chargeItem;
       }
      
       @Remove
       @Destroy
       public void destroy() {
       // nothing to clean up here
       }
      }
      

      @Stateful
      @Conversational(ifNotBegunOutcome = "notbegun")
      @Name("managementAction")
      public class ManagementActionBean implements ManagementAction {
      
       @PersistenceContext
       private EntityManager em;
      
       @In(required = false)
       @Out
       private Charge chargeItem;
      
       @In
       private ChargeListAction chargeListAction;
      
       @In(create = true)
       private Conversation conversation;
      
       @Begin
       public String editCharge() {
       chargeItem = em.merge(chargeListAction.getChargeItem());
       return "chargemanagement.detail";
       }
      
       @End
       public String back() {
       return "chargemanagement.tolist";
       }
      
       @Remove
       @Destroy
       public void destroy() {
       }
      }
      


      Now the problem is that chargeItem is not correctly outjected in the ManagementAction Bean. By writing to stout, I have verified that in ManagementAction#editCharge() the variable is correctly initialized with the selected charge from the ListAction.
      But neither will a jsp display values from that charge nor will ManagementAction#back() work, complaining thusly:

      Out attribute requires value for component: chargeManagementAction.chargeItem
      


      What the heck am I missing here?

      Thanks a lot,

      Phil

        • 1. Re: Problem outjecting a field
          taprogge

          Well, I found the answer, but that raises even further questions...

          It turned out, I had different names for my Charge entity and the fields in my session beans. So the field was not correctly outjected and thus overwritten with null when being injected again on the next method call.
          After naming the field like the Entity's @Name annotation, everything works fine.

          But I am wondering... how then does one go about having two different instances of one Seam component outjected in the same page?
          Imagine you have two car entities in a cataloge and want to present them side-by-side on a single page. The corresponding session bean would have to have two variables car1 and car2 that store the entities. How can you get them both outjected if the field must be named like the entity?

          Any insights would be very much appreciated.

          Regards,

          Phil

          • 2. Re: Problem outjecting a field

            Look at value attribute of @Out and @In annotations. It lets you specify name of the component. So you can do something like this:

            @Out(value="charge1")
            private Charge chargeItem1;
            
            @Out(value="charge2")
            private Charge chargeItem2;
            
            


            • 3. Re: Problem outjecting a field
              taprogge

              Thanks, that was exactly what I was looking for :)

              Regards,

              Phil

              • 4. Re: Problem outjecting a field
                texan

                Or, you can use the @Roles annotation in the bean itself to indicate that it has more than one name (and possibly different scope for each name)