Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
reload a page periodically
Hi,
what'is the best way to reload a table from database periodically, traditionaly i add :
<meta id="meta1" content="30" http-equiv="Refresh"/>
;
i try whith javascript :
setTimeout but this not work with :
mainWindow.executeJavaScript
Regards
Walid
Hi,
I work in the same project with Walid
I used the refresher.jar like in the picture but when i run it, it loops without result.
can you help me please.
Thanks
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Refresher</display-name>
<context-param>
<description>
Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>Refresher</servlet-name>
<servlet-class>
com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<description>
Vaadin application class to start</description>
<param-name>application</param-name>
<param-value>org.vaadin.henrik.refresher.RefresherApplication</param-value>
</init-param>
<init-param>
<description>
Application widgetset</description>
<param-name>widgetset</param-name>
<param-value>com.vaadin.incubator.refresher.RefresherApplicationWidgetset</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Refresher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Hi guys,
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.
HTH,
/Jonatan
solved by the progress indicator sample :
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);
}
Hi all,
I tryed another way:
a (css)hidden NativeButton with ID set via setDebugId()
automatically "clicked" via javascript with:
String script = "setTimeout(\"document.getElementById('btnRefresh').click()\","+ MilliSec + ")";
getMainWindow().executeJavaScript(script);
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.
Any suggestion is welcome!
Carlo
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, ...).
Carlo Greco: 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.
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).
Henri Sara: If I remember correctly, you can register a listener for the progress indicator refresh requests if you want to do them explicitly.
Trying to learn from demos, I was missing this point.
Thank you!