5 Replies Latest reply on Jun 17, 2010 4:16 AM by BhaskerChari

    How to set session variable and How to retire session variable

    Magesh R

      Hi Friends,

       

       

      I want Session variable in my application.Ie After Login how to set Session variable to user name in login page and How to retire Session variable in some other pages..Any one Help tp me...

       

       

       

       

      Thanks,

      Magesh R.

        • 1. Re: How to set session variable and How to retire session variable
          BhaskerChari Level 4

          Hi Magesh ,

           

          Actually what is your question...Is your requirement is to set a session timeout for the logged in user..?

           

          So that if the user is idle for certain period of time the application should force user to relogin..??

           

          Thanks,

          Bhasker Chari

          • 2. Re: How to set session variable and How to retire session variable
            Magesh R Level 1

            Hi  BaskerChari,

             

             

            I want How to make session in flex. For example After login ,how to store username  to session .

             

             

             

             

             

            Thanks,

            Magesh R.

            • 3. Re: How to set session variable and How to retire session variable
              BhaskerChari Level 4

              Hi Magesh,

               

              I dont think you need any session for this ....to store user info.

               

              Create one class something as below which includes values you want to store:

               

              public class UsersVO

              {
                public var useName:int;
                public var firstName:String="";
                public var middleName:String="";
                public var lastName:String="";
                public var emailId:String="";
               

              }

               

              If you are using any SingletonClass as such like ModelLocator Class then create one reference of UserVO classin ModelLocator and try setting the info after the user is successfull logged in.

               

              Say in your Login.mxml file you should do as below:

               

              private var model:ModelLocator = ModelLocator.getInstance();

               

              model.userVO.useName = "magesh';

              model.userVO.emaiId = "magesh@gmail.com';

              model.userVO.firstName = "magesh';

               

              Here userVO is the instance of UserVO class declared in ModelLocator class.

               

              So by doing this you can access the user related info by creating an instance of ModelLocator class any where in your application as below:

               

              private var appModel:ModelLocator = ModelLocator.getInstance();

               

              var userName:String = appModel.userVO.useName;

               

              ----------------------------------------------------------------------------------------

               

              If you are not using any SingletonClass then you can declare the userVO variable in main mxml file and set the values after successful login...and can access it any where by using Application.application.

               

              Say in your login component you want to store the values you can do this:

               

              Application.application.userVO.userVO.useName = "magesh';

              Application.application.userVO.userVO.emaiId = "magesh@gmail.com';

              Application.application.userVO.userVO.firstName = "magesh';

               

              and you can access the values the same way any wher in your application :

               

              var userName:String = Application.application.userVO.userVO.useName

               

               

              Hope this makes things clear...

               

              If this post answers your question or helps, please kindly mark it as such.


              Thanks,

              Bhasker Chari

              • 4. Re: How to set session variable and How to retire session variable
                Magesh R Level 1

                Hi BhaskarChari,

                 

                 

                I got  Error is:"Access of possibly undefined property application through a reference with static type Class.
                -application" from the below line:

                Application.application.UserInfo.UserName="Test";

                 

                Code:

                 

                package com.istmanagement.vo
                {
                public class ISTLogin
                {
                  public var UserName:String="";
                }
                }

                 

                Login.mxml:

                 

                public function handlelogonResult(event):void
                {
                public  var UserInfo:ISTLogin;
                Application.application.UserInfo.UserName="Test";

                }

                 

                 

                 

                 

                 

                 

                 

                 

                 

                Thanks,

                Magesh R.

                • 5. Re: How to set session variable and How to retire session variable
                  BhaskerChari Level 4

                  Hi Magesh,

                   

                  You should declare public  var UserInfo:ISTLogin; in Main mxml application file...

                   

                  If you Login.mxml application file is Login.mxml then it is correct...but if your main application file is different then declare the line in your main mxml file...and your function should like as below:

                   

                  public function handlelogonResult(event):void
                  {
                       Application.application.UserInfo.UserName="Test";

                  }

                   

                  Also import the namespace mx.core.Application in Login.mxml and other components where ever you try to access Application.application property.

                   

                   

                  Thanks,

                  Bhasker Chari