Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GXT: How to bring the login page when session expires

Tags:

gwt

gxt

I am developing a web application using GXT, Hibernate, mysql etc. There is a login page for the application. Actually I am getting problem to set the login page when the session expires. We can set the timeout in the web.xml file but in that case we can't redirect to login page.Can you tell me how to achieve that.

like image 751
dhiraj Avatar asked May 04 '10 08:05

dhiraj


4 Answers

You can not do a server side redirect because the application is entirely AJAX. What you can do is use the GWT Timer class and for every one of your RPC calls check/reset the timer. If the "session" expires then you do a redirect to the login page via a History token. This was the easiest way for me

Some other reading:

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/b9eab8daaa993c83/d0192d356045e061?pli=1

http://gwt-ext.com/forum/viewtopic.php?f=9&t=1682

like image 58
stan229 Avatar answered Nov 08 '22 23:11

stan229


I have used the concept of throwing an exception in the server side when the session expires and then tried to catch the exception in the client side. I don't know whether there is any better way to do that.

like image 20
dhiraj Avatar answered Nov 09 '22 00:11

dhiraj


On the server side, you can check if the session is expired and if so, throw a custom exception. On the client side, on every async call you do a check for this known situation and react to it. You can create an abstract class for AsyncCallback that you will subclass for each GWT RPC call:

public abstract class SessionExpiredAwareAsyncCallback<T> implements AsyncCallback<T> {

    @Override
    public void onSuccess(T returnObject) {
        doOnSuccess(returnObject);
    }

    @Override
    public void onFailure(Throwable exception) {
        if (exception instanceof SessionExpiredException) {
            goToLoginPage();
        } else {
            doOnFailure(exception);
        }
    }

    public abstract doOnSuccess(T returnObject);

    public abstract doOnFailure(Throwable exception);
}
like image 34
Nicolae Albu Avatar answered Nov 09 '22 00:11

Nicolae Albu


You can use gwteventservice to fire an event from the server to the client.

like image 38
Skazi Avatar answered Nov 08 '22 23:11

Skazi