如何在Vaadin中使用PollListener? [英] How to use PollListener in vaadin?

查看:148
本文介绍了如何在Vaadin中使用PollListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码在vaadin中使用PollListener:

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
            }
        });
    }
}

当我打开我的应用程序时,输出"TEST POLL 0"被打印一次.就是这样.我可能错过了什么?

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

推荐答案

您无需执行任何操作,

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

因此,在下次轮询发生时,您在应用程序中所做的任何操作都会在客户端浏览器上更新.在示例中,您应该看到该标签在加载UI后5秒钟后显示,没有任何特殊的用户交互.

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.

但是,如果您需要针对每个此类请求执行一些代码,则可以添加pollingListener

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");
        }
    });
}

这篇关于如何在Vaadin中使用PollListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆