2 Replies Latest reply on Dec 22, 2010 4:18 PM by Monkey Den

    Use @In annotation to get a existing component, but get null...

    Ziyang Zhang Newbie

      I stored all user related data in a session-scoped component called identity.
      In another class, I want to use the identity.
      So I wrote



          @In
          CV2Identity identity;





      And I also wrote



             public int getAccountMissingCount() {
                  int count = m_oDao.getAccountMissingCount(identity.getCVClientID());
                  return count;
              }



      When this method is invoked by a xhtml page, it will run successfully.
      But if I try to invoke this method in another method, like



          public void Chart(OutputStream out, Object data) throws IOException {   
              int nOutputVerifiedCount = getAccountMissingCount();
              //more code
              }





      the identity in getAccountMissingCount() is null, and I get NullPointerException.


      I'm new to seam. Could anybody tell me why identity is null sometimes?



        • 1. Re: Use @In annotation to get a existing component, but get null...
          Leo van den berg Master

          Hi,


          I assume that you have different methods getAccountMissingCount() because I see two different signatures. The Seam interception only works on directly called methods or if you lookup a component, so if that's not the case you will get a null,because Seam didn't had the chance to inject the variable.


          Send some code on how you call the mentioned methods if you want some more help.


          Leo

          • 2. Re: Use @In annotation to get a existing component, but get null...
            Monkey Den Master

            Unless you're overriding the existing Seam Identity object, using:

            @Install(precedence=Install.APPLICATION)

            for example, you might want to change the Seam component name of your CV2Identity object.  Seam injects components by Seam component name and there is already one named identity in the Seam framework, though it is namespaced (org.jboss.seam.security.identity). 


            You might also want to ensure that you aren't trying to do this in a class which has the BypassInterceptors annotation.  Bijection is ignored with this annotation.  If you are, use Component.getInstance(seamComponentName) instead.