2

I'm trying to use the refresher addon in vaadin. But the refresh method is never executed. What am I missing?

@VaadinUI
@PreserveOnRefresh
public class RootUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        REFRESHER.setRefreshInterval(500);
        REFRESHER.addListener(new ChatRefreshListener());
        addExtension(REFRESHER);
    }

    public static final Refresher REFRESHER = new Refresher();

    public class ChatRefreshListener implements RefreshListener {
        @Override
        public void refresh(final Refresher source) {
            System.out.println("test"); //this is never executed
        }
    }
}

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class MyApp extends SpringBootServletInitializer { 
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(MyApp.class);
}
}

<vaadin.version>7.4.0.alpha2</vaadin.version>

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • 1) What Vaadin version are you using? 2) Share your web-app config, either `web.xml` or annotation based – Morfic Jun 23 '14 at 09:34
  • I'm referring to the `web.xml` or `@VaadinServletConfiguration`. More info: https://vaadin.com/book/vaadin7/-/page/application.environment.html and https://vaadin.com/wiki/-/wiki/Main/Creating+a+servlet+3.0+application – Morfic Jun 23 '14 at 09:44
  • I'm using `vaadin4spring` addon (https://github.com/peholmst/vaadin4spring) which requires only the `SpringAwareVaadinServlet` to be configured. I don't have any extra web.xml or servlet configuration classes. – membersound Jun 23 '14 at 09:47
  • You may need to use `@Widgetset` and make sure your xml includes the addon. You can see see the example in the vaadin4spring repo: https://github.com/peholmst/vaadin4spring/blob/master/spring-boot-sample/src/main/java/org/vaadin/spring/boot/sample/Application.java – Morfic Jun 23 '14 at 09:59
  • Would I have to apply any further steps? I tried `@Widgetset(value = "com.github.wolfie.refresher.RefresherApplicationWidgetset")` but still the refresh is not called. – membersound Jun 23 '14 at 10:04
  • Yes, you need to compile the widgeset. Same sample project has the pom config in `src/main` and you need to run `mvn clean vaadin:compile` (https://vaadin.com/book/vaadin7/-/page/clientside.compiling.html) – Morfic Jun 23 '14 at 10:09

1 Answers1

4

First off, using an Extension in a constant is very dangerous at best, but most probably will flat-out not work.

But most importantly, I've deprecated Refresher in favor of UI.setPollInterval() which was introduced in Vaadin 7.1. Vaadin 7.2 (I think) introduced a PollListener, so you now get events for each poll as well.

I guess I should make that deprecation explicit now that Refresher is finally 100% integrated into Vaadin.

Henrik Paul
  • 66,919
  • 31
  • 85
  • 96
  • Thanks, yes of course in production I'd have the extension injected by `Spring` or sort of. Anyhow, could you point me to an example of `PollListener`? I somehow cannot find any hints on how to use this class... – membersound Jun 23 '14 at 10:00
  • Or are we talking about the `@Push` vaadin feature? In this case, I'm trying to find an alternative as the push feature does not work with vaadin4spring addon so far. – membersound Jun 23 '14 at 10:03
  • 2
    @HenrikPaul most likely it's a widgeset config issue which he'd encounter with other add-ons as well if not resolved. +1 for the update on the refresher integration. membersound I think Paul is referring to https://vaadin.com/wiki/-/wiki/Main/Using+polling – Morfic Jun 23 '14 at 10:05
  • Ok, at least the polling works a single time. I created a new quesiton on how to use `PollListener` correctly: http://stackoverflow.com/questions/24363588/how-to-use-polllistener-in-vaadin – membersound Jun 23 '14 at 10:24