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);
- UI.getCurrent().setPollInterval(3000);
- 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?