2 Replies Latest reply on Apr 1, 2008 7:47 AM by AleksandarBalalovski

    Flex session handling

    AleksandarBalalovski
      Hello,

      I have this Java code that runs on Tomcat on the server, and a client application that gets info on the Objects from the server via RemoteObject. Now I need to create a object and then pass it to the next .mxml file, which means, I need something like:

      HttpSession session=request.getSession(true);
      session.setAttribute("userName", sessUsername);

      WHich in Java puts the sessUsername string in the 'userName' attribute in the session. Then from the next file I get this as:
      String cgins;
      cgins=(String)session.getAttribute("userName");

      So then I can call methods from the next file in the session via cgins Object that got its init. from the attribute the 'userName' attribute.

      Now, for Flex I tried something like that in my Java code, with:

      public FlexSession flexSess;
      // flexSess is global FlexSession object
      String sessId=new String();
      flexSess = FlexContext.getFlexSession();
      sessId = (String) flexSess.getId();
      flexSess.setAttribute("username", label1.text);

      And then from another method (defined/implemented in the same class) I try to get access to the 'username' attribute:

      String username=(String)flexSess.getAttribute("username");

      This doesn't work :( It throws NullPointer exception.

      Can u tell me if I am doing this right, and if not what is the recommended way to handle session attributes in Java code for Flex which can be reused and not created new objects.

      thanks
        • 1. Re: Flex session handling
          riesvantwisk Level 1
          Hey,

          I am doing exactly the same and that works for me. So I think I can tell you you are doing the right thing there.

          However, what is label1.text ?? is label1 a object or something?? Are you sure (debug!!!) that you are not putting null in the session in the first place?

          Ries
          • 2. Flex session handling
            AleksandarBalalovski Level 1
            label1.text is a text form a mx:label object :/

            Yes I am sure that I am not putting 0 to the session attribute.

            The initial error I get:
            [RPC Fault faultString="java.lang.NullPointerException : null" faultCode="Server.Processing" faultDetail="null"]


            Do you have the both methods (the one where the attribute is set and the one where the attribute is taken/"get") in one same class/file?
            thanks