views:

115

answers:

2

Hello guys,

i am using gwt to create a web application.

when a user presses the logout button, i want to be able to refresh the page(or basically redirect to the homepage)as my GWT application runs only on one html page.

what is the programmatic code to do this?

+5  A: 

You want to use Window.Location.assign() to tell the browser to go to a URL, such as a URL pointing to a servlet that logs out the user.

Jason Hall
A: 

You could use

//redirect the browser to the given url. Native method

public static native void redirect(String url)/*-{
      $wnd.location = url;
  }-*/;

//Example call

redirect("http://www.example.com/");
markovuksanovic
Actually, even in JS the correct method would be `$wnd.location.assign(url)` (see https://developer.mozilla.org/en/DOM/window.location) -- which happens to be exactly what GWT's `Window.Location.assign()` does (see Window.java here: http://google-web-toolkit.googlecode.com/svn/trunk/user/src/com/google/gwt/user/client/ line 130)
Jason Hall
Didn't notice that method. Thanks for the tip.
markovuksanovic