4 Replies Latest reply on May 19, 2009 4:48 PM by GT Nguyen

    Injecting application-scope variable

    GT Nguyen Newbie

      Hello there,


      I have a singleton that auto-starts and stores some database values in application-scope variables.


      When I try to access the variables on the HTML page, it works fine.


      When I try to inject the variables into a Seam Action bean, I get 'null' values.


      I'm new to Seam.  Any help would be appreciated.  Code snippet below.


      Cheers,
      G.T. Nguyen


      @Local
      public interface ApplicationParams
      {
          public void onCreate(Component self);
          public String getTest();
      }
      
      @Name("applicationParams")
      @Startup
      @Scope(ScopeType.APPLICATION)
      
      public class ApplicationParamsBean implements ApplicationParams
      {
          private String test = "";
      
          @Create
          public void onCreate(Component self) {
      
           // retrieve value from database
           test = "something";
          }
      
          public String getTest() {
           return test;
          }
           
      }
      
      
      <ui:composition>
      <ui:define name="body">
        #{applicationParams.test}
      </ui:define> 
      </ui:composition>
      
      
      // Test Bean
      @Stateless
      @Name("test")
      public class TestBean implements Test
      {
           @In("#{applicationParams.test}") private String test;
           // test returns null (???)
      
      }