3 Replies Latest reply on Nov 6, 2008 10:26 PM by nimo stephan

    Get and Set SessionInstance in ConversationInstance

    nimo stephan Master

      How can I retrieve or manipulate (for example) a list from a ConversationContext. The list is stored in my SessionContext.




      @Name("sessionContext")
      @Scope(SESSION)
      public class MySession {
      
              
      @In(required=false)
      @Out (required = false)
      private List<String> sessionList;
              
              
      @Factory(value="thisSession")
      public void init(){
      
      }
              
      }





      and that:


      @Name("conversationContext")
      @Scope(CONVERSATION)
      public class MyConversation {
      
              
      @In(required=false)
      @Out (required = false)
      private List<String> sessionList;
              
      public void accessSessionContext()
      {
      
      //I want access to my sessionContext
      
      org.jboss.seam.core.contexts.sessionContext("sessionContext")
      
      //or that?
      
      (List<String>) Component.getInstance("sessionList")).put("hello");
      
      
      }
              
      }



      How can I get/set the SessionInstance via my ConversationInstance?

        • 1. Re: Get and Set SessionInstance in ConversationInstance
          nimo stephan Master

          This does not work:


          @Name("conversationContext")
          @Scope(CONVERSATION)
          public class MyConversation {
          
          MySession mySession;
                  
          @In(required=false)
          @Out (required = false)
          private List<String> sessionList;
                  
          public void accessSessionContext()
          {
          
          //I want access to my sessionContext
          
          mySession = (MySession) Contexts.getSessionContext().get("sessionContext");
          mySession.sessionList.add("hello");
          
          }



          Anything is wrong..

          • 2. Re: Get and Set SessionInstance in ConversationInstance
            nimo stephan Master

            Okay...now it works!!


            I can get the Session-Instance from my Conversation-Instance:


            first case:


            sessionContext= (MySession) Contexts.getSessionContext().get("sessionContext");
            sessionContext.getSessionList();



            or I can get mySessionList directly:


            second case:


            List<String> mySessionList = (List<String>) Component.getInstance("mySessionList", ScopeType.SESSION);




            both works.


            But what, when I do not provide getter/setter in my sessionContext and use the first case. How can I retrieve mySessionList via my Contexts ?



            sessionContext= (MySession) Contexts.getSessionContext().get("sessionContext");
            sessionContext.XXX ?


            • 3. Re: Get and Set SessionInstance in ConversationInstance
              nimo stephan Master

              What is the difference of this. I invoke both in a Conversation-Scope:


              List<String> myStrings = (List<String>) Component.getInstance("mySessionList", ScopeType.SESSION);




              and that:


              myStrings = (List<String>)Contexts.getSessionContext().get("mySessionList");



              Is the shorter one, the better one?



              Another point is, when I want to put some values into myString:



              List<String> myStrings = (List<String>) Component.getInstance("mySessionList", ScopeType.SESSION);
              myStrings.add("hello");




              then a NullPointerException occurs.


              Any suggestions?