Continuous Refresh at client side?

Hi!
I am not sure how you, guys, generally doing continuous refresh of something at the canvas? In my case I need to refresh each NN seconds a set of messages. I know how to do it in a plain GWT, but when I am using a general Thread with while(true) {…} inside, then it works but never refreshes, unless I press F5 in browser (refresh).

How to generally Vaadin refreshes e.g. an image (e.g. from webcam somewhere) or similar sort of things?

Thanks!

You can use
Refresher

you can also use built-in progress indicator to avoid adding a new widget to the project and recompile the widgetset. To hide it from the UI, just make it invisible via CSS (but only via CSS, as setVisible(false) will disable polling)

Dmitri, thanks.
So it is just that easy: setPollingInterval(…). Nice.

A rhetorical question to the core developers: why not add something like:

window.setAutoRefresh(...)

…where you can pass some parameters, like an interface of some callback and an interval, for example? That would probably avoid entire Refresher plug-in as well as all these CSS games with not-so-really-related progress widget. I think periodical refresh is quite often needed: you want to show some pictures or do stuff like Twitter messages animation etc. I think nice would be to have something like:

int interval = 500;
this.getMainWindow().setAutoRefresh(new AutoRefreshExecutor() {
    public void execute() {
        // Do something useful here each [interval]
 times.
    }
}, interval);
this.getMainWindow.setAutoRefreshable(true); // False by default

I just thought if somebody would merge all the Refresher code into new Vaadin like that, could be probably good?

Like the idea of autorefresh executor, this could simplify things in mosts cases, avoiding creating and handling a server thread in case it is not so needed (if your data-update code is fast)

Hey, guys,
BTW, no special CSS games needed either. Just make width/height of the process indicator to zero. :slight_smile: I did it this way a little Refresher, that works fine, as long you don’t need put some executor on top of it:

public class NanoRefresher extends ProgressIndicator {
    public NanoRefresher(int interval) {
        this.setPollingInterval(interval);
        this.setWidth("0px");
        this.setHeight("0px");
    }
}

This thing looks like works properly everywhere (Presto, KHTML, WebKit, Gecko, Trident) since tested myself. :slight_smile: Usage is also dead-simple:

mainWindow.addComponent(new NanoRefresher(500));

I think there’s a ticket for this specific feature already in the Trac:
#4056: Add Window.setRefreshRate to enable automatic UI updates

Feel free to add comments to that ticket if it’s not exactly as you’d wish. Thanks!

In vaadin 7.1 use


UI.setPollInterval(1000).

This will make the client browser, poll the vaadin server, every 1 sec, for any UI changes.

e.g. Say you are adding a new table row, using a thread which polls your backend database, for new items.
Without the above call, after you have added the new table row, the browser will not show the row, if left alone.
The user needs to do some operation in the browser, to get the new row visible.
With this call it will automatically appear on the browser.