How to use PollListener in vaadin?

為{幸葍}努か 提交于 2020-01-05 05:09:48

问题


I'm trying to use PollListener in vaadin with following code:

@VaadinUI
@PreserveOnRefresh
public class ApplicationUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        setPollInterval(1000);
        access(new Runnable() {
            @Override
            public void run() {
                System.out.println("TEST POLL: " + counter++); //is only printed a single time
            }
        });
    }
}

The output "TEST POLL 0" is printed a single time when I open my application. But that's it. What might I have missed?


回答1:


You don't have to do anything, the polling example specifically states that:

By doing this the browser will poll the server each "timeout" ms and retrieve any possibly pending changes

So, whatever you did in you application will be updated on the client browser when the next polling occurs. In the example you should see that label being displayed 5 seconds later after the UI has loaded, without any special user interaction.

However if you need to execute some code with each such request, then you can add a pollingListener

@Override
protected void init(VaadinRequest request) {
    setPollInterval(1000);
    addPollListener(new UIEvents.PollListener() {
        @Override
        public void poll(UIEvents.PollEvent event) {
            log.debug("Polling");
        }
    });
}


来源:https://stackoverflow.com/questions/24363588/how-to-use-polllistener-in-vaadin

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