2 Replies Latest reply on Oct 28, 2005 10:45 AM by Phil Miller

    @Out scope question

    Phil Miller Newbie

      Hi, I am setting a session scoped entity, a Participant, through outjection, like this:

      @Stateless
      @Name("login")
      @Interceptor(SeamInterceptor.class)
      public class LoginAction implements Login {
      
       @Out(scope = ScopeType.SESSION, required = false)
       private Participant participant;
      
       @In
       private Context sessionContext;
      
      ..................
      
       @IfInvalid(outcome = REDISPLAY)
       public String login() {
      
      .................
       participant = results.get(0);
       log.info("participant loaded: " + participant);
      
       sessionContext.set("loggedIn", true);
       // sessionContext.set("p",participant);
       return "overview";
      ...................
      
      


      I set 'required=false' on the @Out annotation for the case where the login is invalid, and Seam redirects back to the login page. I know from logging that my Participant is not null.

      I had thought that a subsequent stateful conversational component would be able to access this '@Out-jected' Participant through '@In-jection', like:

      @Stateful
      @Name("wow")
      @Interceptor(SeamInterceptor.class)
      @Conversational(ifNotBegunOutcome = "home")
      @LoggedIn
      public class WOWImpl implements WOW, Serializable {
      
      
       @In(scope=ScopeType.SESSION, create=false, required=true)
       private Participant participant;
      
       @In
       private Context sessionContext;
      
      ................
      
      


      But in this case, Participant is null, and.. the sessionContext is also null.

      I know that I can explicitly get a not-null reference in the stateful via:
      participant = (Participant) Contexts.getSessionContext().get("participant");
      But this seems less elegant.

      I think the clue here is that the stateful bean has a null injected sessionContext, whereas the stateless bean has a valid reference, but I can't figure it out yet..

      Anyway, is my thinking wrong in the way @Out-jection works in this case?

      Cheers, and thanks for the product!
      Phil



        • 1. Re: @Out scope question
          Gavin King Master

          Perhaps you need to add @Intercept(ALWAYS)

          • 2. Re: @Out scope question
            Phil Miller Newbie

            Doh! Many thanks Gavin, that works.

            I added:

            @Stateful
            @Name("wow")
            @Interceptor(SeamInterceptor.class)@Intercept(InterceptionType.ALWAYS)@Conversational(ifNotBegunOutcome = "home")
            @LoggedIn
            public class WOWImpl implements WOW, Serializable {
            
             @In(scope = ScopeType.SESSION, required = true, create = false)
             private Participant participant;
            
             @In(create = true, required = true)
             private Context sessionContext;
            
            


            And now my Participant entity has been injected into this SFSB from session context. So no more need for this:
            participant = (Participant) Contexts.getSessionContext().get("participant");

            Thanks again,
            Phil