3 Replies Latest reply on Jan 19, 2011 6:40 PM by nraf

    Injection vs. Component.getInstance()

    daxxy

      I'm trying to understand something.


      I write a custom envers RevisionListener in which I need access to the seam identity component from the Session context.  The following code works:




      public class IdentityListener implements RevisionListener {
      
              public void newRevision(Object revisionEntity) {
                      Identity id = (Identity) Contexts.getSessionContext().get("org.jboss.seam.security.identity");
                      IdentityRevisionEntity revEntity = (IdentityRevisionEntity) revisionEntity;
              }       
      
      }
      




      Before that, however, I tried injecting the session context using




      @In
      Context sessionContext



      and various other components, context variables, etc., but in every case got null.


      What is special about this class that injection does not work?  I tried making it into a Seam component, but that didn't help either.


      Can someone explain what I'm assuming is something basic to seam and/or java?


      TDR

        • 1. Re: Injection vs. Component.getInstance()
          cbensemann

          Hi,


          I assume your revisionListener isn't a seam component (i.e. its not annotated with @Name). Seam is only able to inject objects into classes that are managed by seam. Also injection will not work on any class marked with @BypassInterceptors annotation. In these cases you can use one of the org.jboss.seam.Component.getInstance() methods to get hold of your seam objects.



          Craig

          • 2. Re: Injection vs. Component.getInstance()
            daxxy

            Same problem even if I make it a seam component.

            • 3. Re: Injection vs. Component.getInstance()
              nraf

              I'm having a similar issue. I've registered an event listener (using Events.instance().raiseASynchronousEvent(...)') and am trying to get some Seam components using Component.getInstance(). The objects are coming back but all their values are either 0 or null.