3 Replies Latest reply on Sep 23, 2009 9:50 PM by Madhav Subedi

    Browser Refresh and Retaining View State

    Rajesh Subbiah

      Hi ,

       

       

      I am developing a web-based application in flex.

      I am facing a problem i.e. i have all my modules in a view stack like shown below

       

          <mx:ViewStack 
             id="appView"
             selectedChild="{ getView( model.workflowState ) }">

       

              <view:LoginPanel id="login" login="{ model.login }"/>

       

              <mx:VBox id="loggedIn" width="100%" height="100%">
              
           
              
                 <!-- The Main Screen -->
                    
              </mx:VBox>

       

          </mx:ViewStack>

       

       

      Once the user logs in i show a different view  i.e the main Screen (only for successful login ).

      Now if the user logs in and does a browser refresh , the complete application reloads again . How to avoid that ....

       

      Is the approach correct (ie use of view stack )

       

      Kindly help me to solve this issue

        • 1. Re: Browser Refresh and Retaining View State
          Madhav Subedi Level 4

          when user refreshes the browser, it will definitely load the whole application again.

           

          however, your aim seems to avoid showing login box if user has already logged in right?

           

          for this use server side sessions, and in application initialize, send a request to check if session is LOGGED.

           

          depending on that, set the selectedChild of viewstack.

          • 2. Re: Browser Refresh and Retaining View State
            Rajesh Subbiah Level 1

            Hi Madhav ,

             

                      What request i need to send at the time of application initialize.

             

                      Can you give some sample example or any other tutorial .

            • 3. Re: Browser Refresh and Retaining View State
              Madhav Subedi Level 4

              private function checkLogged():void
              {
                   var hs:HTTPService = new HTTPService();
                   hs.url = "checkLogin.php";
                   hs.addEventListener(FaultEvent.FAULT,fault);
                   hs.addEventListener(ResultEvent.RESULT,resultChkLoggedIn);
                   hs.send();
              }
              
              private function resultChkLoggedIn(e:ResultEvent):void
              {
                   if(e.result.logged == true)
                   {
                        // logged state 
                   }
                   else
                   {
                        // display login pannel.
                   }
              }
              
              ///////////// checkLogin.php
              
              if($_SESSION['logged'] == "Y")
              {
                   echo "<logged>".true."</logged>";
              }
              else
              {
                   echo "<logged>".false."</logged>";
              }