2 Replies Latest reply on Jun 27, 2007 2:59 AM by statelessbean

    Howto: acces from bean to another SFSB?

    statelessbean

      hi,
      I have authenticator method, and afterr successfull login user is redirected to second page.
      On second page some values are getted from bean "gameAction" (SFSB).

      I thought that to create this SFSB in authenticator bean and set this values and inject this bean to session.

      Here I found an example how to access to bean from another bean.

      Map session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
       GameAction backBean = (GameAction)session.get("gameAction");
      

      when user first time login my GameAction bean is always null so, i check this and create my new bean.

       if (backBean == null) {
       backBean = new GameAction(Long id, String name);
       backBean.setPlanetName("Earth");
       session.put("gameAction", backBean);
       }
      


      and on my page i get planetName like <h:output....

      Is this right idea? or maybe is better way to create new bean and set fields?



        • 1. Re: Howto: acces from bean to another SFSB?
          delphi'sghost

          If I'm understanding your question, you could just use a factory method to create the bean and initialize it on demand.

          @Factory(name="gameAction",scope=SESSION)
          public GameAction initGameAction() {
          
           GameAction result = new GameAction(someId,someName);
           return result;
          }
          


          When you inject it simply specifiy that you want to create it if it doesn't exist.

           //in some other bean
           @In(create=true)
           private GameAction gameAction;
          







          • 2. Re: Howto: acces from bean to another SFSB?
            statelessbean

            Can U explain me for what reason u use @Factory here? What this do?

            @Factory(name="gameAction",scope=SESSION)
            public GameAction initGameAction() {
            
             GameAction result = new GameAction(someId,someName);
             return result;
            }
            


            Maybe better way is to create in method my bean and outject using @Out like
             //in some other bean
             @Out
             private GameAction gameAction;