what’is the best way to reload a table from database periodically, traditionaly i add :
<meta id="meta1" content="30" http-equiv="Refresh"/>
[/code];
i try whith javascript :
setTimeout but this not work with : [code]
mainWindow.executeJavaScript
You actually need to also start a background thread that actually updates the table. The Refresher component only polls for UI changes, but nothing will happen if there are none (i.e. nothing will happen if the table’s items haven’t changed).
Remember to synchronize on your Application instance when you modify UI components from a background thread.
public class Worker1 extends Thread {
int current = 1;
public final static int MAX = 20;
@Override
public void run() {
boolean b = true;
while (b) {
current = 1;
pi1.setEnabled(true);
pi1.setValue(0f);
for (; current <= MAX; current++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// All modifications to Vaadin components should be synchronized
// over application instance. For normal requests this is done
// by the servlet. Here we are changing the application state
// via a separate thread.
synchronized (mainWindow.getApplication()) {
prosessed();
}
}
System.out.println("OK");
String d = FctDate.dateToString((Date) datePopup.getValue(), "dd/MM/yy");
synchronized (mainWindow.getApplication()) {
prosessed2(d);
}
}
}
private void prosessed2(String d) {
tabledb.refreshTable(d);
}
It’s trivial but does not require Refresher, or ProgressIndicator and new threads.
Before this, I tried the ProgressIndicator way, and I fear that, once started, the new thread will remain active even when user leaves the page.
I think to remember that the debug ids are stripped when running the release build (as they are for debug purpose). I would not rely on them for anything as it may end up having strange effects when put in production (broken CSS, broken javascript, …).
ProgressIndicator does not use new threads either on the server or on the client. It sets up a timer on the client side which triggers a (practically empty) request to the server, just to allow the server to respond as the server cannot initiate connections. Your button clicks effectively do the same except that the request actually has a slightly different payload (“this button was clicked”). If I remember correctly, you can register a listener for the progress indicator refresh requests if you want to do them explicitly.
ProgressIndicator then resets the timer whenever it is triggered to achieve periodic refreshes. The timer only gets used and reset while it is on the visible page, so if you want it to be active in all views of your application, you should place it in some root layout that does not get changed (or in some other layout in each view).