views:

35

answers:

1

How can we achieve what the below HTML meta tag can do, in GWT?

<meta http-equiv="refresh" content="30" />
+2  A: 

If you want the browser to automatically refresh every 30 seconds, you can accomplish that with:

new Timer() {
  @Override
  public void run() {
    Window.Location.refresh();
  }
}.schedule(30000); // milliseconds

This is using schedule() instead of scheduleRepeating() because reloading the page like this will cause your GWT code to stop and restart fresh from the beginning. You probably want to avoid this.

I'll be honest, this practice "smells" pretty bad to me. If you give a little more information about why you would want to refresh the page every 30 seconds (thus requiring your GWT code to be reloaded), I can probably give you advice about how to better do what you want to do.

Jason Hall
Agreed, this is not good practice. You should use Timer to schedule a service call, rather than a page refresh, that downloads just the data which is likely to have changed in the last 30 seconds. Then programmatically refresh just the portions of the page that need it. This will give you a much nicer user experience and much less redundant downloading of static content.
hambend
@ hambend I have a just a big ugly table without pagination, on that screen. And I load up just that specific panel on which the table thrives.
frappuccino
@Jason I am using the timer. Have a weird requirement where the user wants to sit and gaze at a screen, while the page load should refresh to post the latest status. (It gets updated by a background process)
frappuccino
@frappuccino The better solution would be to have the Timer trigger a call to fetch the table's data (e.g., by calling to an RPC service to get the latest data) then repopulate the table with that new data.
Jason Hall
@jason doing exactly that...thanks
frappuccino