3 Replies Latest reply on Aug 9, 2007 4:19 AM by Fredrik Forsberg

    @In annotation on attributes resolves to null

    Fredrik Forsberg Newbie

      Hello. I use seam 2.0 B1, jboss AS 4.2 and Facelets Sun RI.

      I have a facelets jsf file called showmessages.xhtml, a stateless seam component called CellIdBean and an stateful seam component called MessagesActionBean.

      My use case is simply to load messages from db in the MessagesActionBean and show them in the messages.xhtml. The special thing is that the xhtml will consist of several facelets includes that has their own id. (Therefor I cannot use the id with a page parameter in pages.xml). I want to pass the ids many times in the messages.xhtml to the MessagesActionBean by using the CellIdBean as a "DTO" and inject this CellIdBean in the action with @In.

      This solution might sound unnecessarily complex but if I try just to set the cellId directly in the MessagesActionBean with

      messagemanager.setCellId(cellid)


      then I get a complaint in the method initMessages about the cellId being null when initMessages is executed (it has an @create annotation).
      The setCellId is then not even run. I guess that the @create methods are run before the setters of the properties are run? Am i wrong?

      Anyway, instead I tried this way (with the "DTO")


      #{cellidbean.setCellId(cell.id)}



      The cellidbean component is created and the cellid is set in the component CellIdBean (below).

      @Stateless
      @Name("cellidbean")
      public class CellIdBean implements CellIdBeanLocal {
      
       @In(create = true)
       private Long cellId;
      
       public CellIdBean() {
       }
      
       public void setCellId(Long cellId) {
       this.cellId = cellId;
       }
      
       public Long getCellId() {
       return cellId;
       }
      }



      But when I try to use this cellidbean in my actionclass MessagesActionBean it is resolved to null

      @Name("messagemanager")
      @javax.ejb.Stateful
      public class MessageActionBean implements MessageActionLocal {
       @In(create = true) // <-- this resolves to null
       private CellIdBeanLocal cellIdBean;
      
      
       .
       .
       .
       constructors
       .
       .
       .
      
      
       @Override
       @Create
       protected void handleInitMessages() {
       // get messages for the requesting cell
       }
      
      }


      Why is the injection of cellidbean in messageactionbean not done?

      thank you