Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    how to use session in smartgwt

    Hi,
    I want to use session in a smartgwt program(e.g. HelloWorld program). How to use session?

    Please help me.

    Regards,
    Nobel.
    Last edited by nobel; 26 Apr 2011, 03:54.

    #2
    What are you look to do with a session? If you're looking to store variables throughout the life of a session, GWT gives that to you automatically, since Client-only code is by definition session unique. If you create a client-only GWT singleton class, that instance will persist throughout the life of the session.

    For example, create a client-only class called LogIn. When you log in, assign the user to that class --

    LogIn.getInstance().setLoggedInUser(user);

    Then, for the entire life of the session, if you get the user, it will be set --

    LogIn.getInstance().getLoggedInUser();

    will return what you set initially.

    Sorry if this isn't what you were looking for, but since storing session variables is the most common usage of the session, I though I'd throw this out there for you.

    Comment


      #3
      Hi,

      Thanks for your immediate reply.

      I want to store more than one variable's value and retrieve it in another page through session.

      Please give me if you have sample or through complete code explanation.

      Regards,
      Nobel.

      Comment


        #4
        Its not clear what you mean by 'page'. If you mean reloading the page on a different GWT module, you could use a cookie: http://google-web-toolkit.googlecode...t/Cookies.html

        Comment


          #5
          Hi,
          I want to use session in smartgwt for user management, especially for login screen. After submitting the login screen, If the login is successful, i want to save the username as a session value in a session variable. The page redirects to home screen and continues the session. And when i log out, the session has to be removed. How can i do this in smartgwt or gwt?

          Please help me how to do that?

          Thanks in advance,
          Nobel.

          Comment


            #6
            Originally posted by nobel
            Hi,

            Thanks for your immediate reply.

            I want to store more than one variable's value and retrieve it in another page through session.

            Please give me if you have sample or through complete code explanation.

            Regards,
            Nobel.
            Yup, that's no problem. Do this --

            Create a client-only GWT class as a singleton. Put regular properties and getters and setters. Something like this:

            public class MyClass {

            private String var1;
            private String var2;
            static private MyClass _instance = null;

            public MyClass() {}

            public static MyClass getInstance() {

            if (_instance==null) _instance = new MyClass();
            return _instance;
            }

            (getters and setters for var1 and var2

            }


            Now, in your code, you simply set the value by calling the instance --

            MyClass.getInstance().setVar1(value);
            MyClass.getInstance().setVar2(value);

            Then, anyplace you want to retrieve the value, simply use the getters --

            MyClass.getInstance().getVar1();

            and you will get the values. You've created an instance that persists throughout the session.

            Comment


              #7
              Hi SteveSinger,

              Thanks for your guiding. I will implement this session tracking and let u know. Please continue to guide me.

              Thanks,
              Nobel.

              Comment


                #8
                the method described above does not work.When the URL changes ,the values are reset and the above approach is of no use.
                This wasted 3 hours of my very valuable time.
                Please make sure the approach works before forwarding it to others.
                Thanks

                Comment


                  #9
                  Originally posted by nobel
                  Hi,
                  I want to use session in smartgwt for user management, especially for login screen. After submitting the login screen, If the login is successful, i want to save the username as a session value in a session variable. The page redirects to home screen and continues the session. And when i log out, the session has to be removed. How can i do this in smartgwt or gwt?
                  You do not need to create different HTML pages for Login and Main screen. Just create a modal Window for Login screen and show(), hide() if needed.

                  Comment


                    #10
                    Hi,

                    Take a look at this post -> http://uptick.com.au/content/gwt-login-security

                    re GWT login security.

                    Cheers
                    Rob

                    Comment


                      #11
                      Originally posted by Aman
                      the method described above does not work.When the URL changes ,the values are reset and the above approach is of no use.
                      This wasted 3 hours of my very valuable time.
                      Please make sure the approach works before forwarding it to others.
                      Thanks
                      It works fine if you are using the GWT standard of being in a single HTML page for the module and handling the pages and screens with GWT widgets. Sorry you had to waste your "very valuable time."

                      Comment


                        #12
                        You can do by setting cookie

                        Cookie.setCookie("var",username);
                        Cookie.getCookie("var");

                        Comment

                        Working...
                        X