Search code examples
vaadinvaadin7refreshervaadin-refresher

Vaadin refresher extension doesn't work


I am trying to make a simple usage of refresher plug-in as below but it doesn't seem to work. I am tried to run this example in Chrome and in firefox. I am exporting the project as WAR and deploying it in tomcat webapps folder.

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

    }

}

What am I doing wrong here? I also tried the same example with SimpleDateFormat instead of using WebBrowser getCurrentDate() but still the same issue


Solution

  • since vaadin 7.2 you don't need the refesher addon. just enable push support

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