Vaadin复习扩展不起作用

时间:2014-08-03 14:40:55

标签: vaadin vaadin7 refresher vaadin-refresher

我正在尝试简单地使用如下所示的刷新插件,但它似乎不起作用。我试图在Chrome和Firefox中运行此示例。我将项目导出为WAR并将其部署在tomcat webapps文件夹中。

package com.example.vaadinapp;

import javax.servlet.annotation.WebServlet;

import com.github.wolfie.refresher.Refresher;
import com.github.wolfie.refresher.Refresher.RefreshListener;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("vaadinapp")
public class VaadinappUI extends UI {

    Refresher refresher;
    Label timeLabel;
    Page page;

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = VaadinappUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);

        refresher = new Refresher();
        page = this.getPage();
        timeLabel = new Label(String.valueOf(page.getWebBrowser().getCurrentDate()));

        refresher.setRefreshInterval(1000);
        refresher.addListener(new RefreshListener() {
            @Override
            public void refresh(Refresher source) {
                timeLabel.setCaption(String.valueOf(page.getWebBrowser()
                        .getCurrentDate()));
            }
        });
        addExtension(refresher);

        layout.addComponent(timeLabel);

    }

}

我在这里做错了什么?我也使用SimpleDateFormat尝试了相同的示例,而不是使用WebBrowser getCurrentDate(),但仍然存在同样的问题

1 个答案:

答案 0 :(得分:0)

从vaadin 7.2开始,你不需要使用refesher插件。只需启用推送支持

https://vaadin.com/book/vaadin7/-/page/advanced.push.html