6 Replies Latest reply on Oct 22, 2007 10:01 PM by norman.richards

    @Out-jection fails to work in certain conditions - Beware!

      Hi,

      This is an interesting example and I would be grateful if anyone could shed some light on this extremely strange behaviour.

      It seems that in the following example, if an item is an @Entity Pojo on an action class and the entity manager is @In-jected to the same action class (you don't have to use it) then @Out-jection will fail.

      The following simple example will illustrate.

      This simple page will display the value of an item if the item is not null

      <body>
       <f:view>
       <h:form>
       <div><h:commandLink value="New Item" action="#{testPage.newItem}" /></div>
       <s:div rendered="#{testPage.item != null}">
       #{testPage.item.name}
       </s:div>
       <h:commandLink value="Clear Item" action="#{testPage.clearItem}" />
       </h:form>
       </f:view>
      </body>
      


      The testPage action class is as follows

      @Name("testPage")
      @Scope(ScopeType.CONVERSATION)
      public class TestPageAction {
      
       @In EntityManager entityManager;
      
      private Item item;
      
       public Item getItem() {
       return item;
       }
      
       public void setItem(Item item) {
       this.item = item;
       }
      
       @Create
       @Begin(join=true)
       public void newItem() {
       item = new Item();
       item.setName("some item");
       }
      
       public void clearItem() {
       item = null;
       }
      }
      


      Item is as follows
      @Entity
      public class Item {
      
       @Id
       @GeneratedValue
       private long id;
      
       private String name;
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      }
      


      Now this example will fail to remove the item text when you click the Clear Item link and it seems it is because the outjection failed to outject a null value for the item.

      Now the interesting this is if you do ANY of the following the example will work:

      1. Change item to a non @Entity pojo - example works or
      2. Comment out the injection of the EntityManager - example works

      Can anyone shed some light on this? I've spent a lot of time stepping through the seam source and even though after the invoke of the action method the item is set to null it mysteriously gets reset back to a value before outjection occurs.

      Any help would be appreciated

      Thanks

      Troy