UI polling setPollInterval

Hi!

A polling is a constant refresh of the page. Using the function in the UI, setPollInterval(milliseconds), we can frequently update any changes.

I wrote this quick little app to demonstrate. If you want to see in action, just create new project and replace the UI.init method with this init method.

protected void init(VaadinRequest request) {
setPollInterval(1000);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
    
    addPollListener(new UIEvents.PollListener() {
        @Override
        public void poll(UIEvents.PollEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
        }
    });
    
    Button button = new Button("Click Me");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
        }
    });
    layout.addComponent(button);
}

Basically, you should now be seeing that every 1 second, a message “Thank you for clicking” is printed.

My problem arises when I have several Navigation views, and I want some refreshment functionality in a view. I get a HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/vaadin/event/UIEvents$PollListener.

Let’s say I have a LoginView extends VerticalLayout implements View.
I suspect it is caused when I run the following statement(s);

  1. UI.getCurrent().setPollInterval(3000);
  2. ui.addPollListener(new UIEvents.PollListener() {
    @Override
    public void poll(UIEvents.PollEvent event) {
    //do specific things here.
    }
    }

Since this worked fine in the quick little “Thanks for clicking” refresher, I strongly believe UI.getCurrent() is the issue. Why?

Hi Harshil, poll listeners are a feature that was introduced in Vaadin 7.2, so if the class is not found, it appears you still have an older Vaadin version deployed on the server either in addition or instead of the newer one. Please check if that is the case.

Thanks Johannes!!

It was resolved. You were correct. I’ll elaborate for anyone in the future that has this problem.

I was playing around with quicktickets-dashboard demo application from vaadin.com that was a 7.1.0 Vaadin version. Now, since I was using an IDE, I quickly figured out that poll listeners are not in 7.1, and I must upgrade. So I clicked on project properties and changed into Vaadin 7.4. All code compiled correctly, so I thought it wouldn’t be a problem. But I guess, it didn’t completely change…I did see the listing for UI.setPollInterval() and UI.addPollListener(), but they wouldn’t function. I created a BRAND NEW 7.4 project and it worked. So thus, I basicallly created a new project and copied all the files over, and voila, it worked. Must have been something to do with dependencies, or pom.xml. I wouldn’t recommend switching Vaadin versions of projects. But it also might have been due to my inexperience/complete lack of knowledge in web app developmet/maven, so don’t trust me. Alas, if all else fails, as learned by my experience, just create a brand new project and copy files over :slight_smile: