VAADIN 7: What is the simplest way to refresh a Vaadin View in 5 minute intervals?

你说的曾经没有我的故事 提交于 2019-12-02 13:20:02

问题


I'm trying to implement an automatic refresh on a List of components in a Vaadin view. The list gets its contents from a database. I can refresh the list with a button, that is already implemented.

However, I would like to know what is the simplest way to make it so, that this refresh event, that I already have, would automatically refresh in 5 minute (300 000 milliseconds) intervals?

Here's what I tried and it keeps refreshing even after I exit the view so it doesn't really work. I'd like the refresh to happen in 5 minute intervals only while that certain view is being shown.

UI myUI = UI.getCurrent();  

            myUI.setPollInterval(300000);
            myUI.addPollListener(event -> {
                refreshList();
            });

How would I make it so that the refresh doesn't happen after navigating to other views? And is there some simpler way to do this in Vaadin? Thank you


回答1:


You could do so that you call

myUI.setPollInterval(300000);

when the view is activated, and you disable it by calling

myUI.setPollInterval(-1);

when another view is activated. If you use Vaadin Navigator, then you could use ViewChangeListener for handling the polling.



来源:https://stackoverflow.com/questions/32249435/vaadin-7-what-is-the-simplest-way-to-refresh-a-vaadin-view-in-5-minute-interval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!