0

I'm trying to use PollListener in vaadin with following code:

@VaadinUI
@PreserveOnRefresh
public class ApplicationUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        setPollInterval(1000);
        access(new Runnable() {
            @Override
            public void run() {
                System.out.println("TEST POLL: " + counter++); //is only printed a single time
            }
        });
    }
}

The output "TEST POLL 0" is printed a single time when I open my application. But that's it. What might I have missed?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

7

You don't have to do anything, the polling example specifically states that:

By doing this the browser will poll the server each "timeout" ms and retrieve any possibly pending changes

So, whatever you did in you application will be updated on the client browser when the next polling occurs. In the example you should see that label being displayed 5 seconds later after the UI has loaded, without any special user interaction.

However if you need to execute some code with each such request, then you can add a pollingListener

@Override
protected void init(VaadinRequest request) {
    setPollInterval(1000);
    addPollListener(new UIEvents.PollListener() {
        @Override
        public void poll(UIEvents.PollEvent event) {
            log.debug("Polling");
        }
    });
}
Morfic
  • 15,178
  • 3
  • 51
  • 61
  • what if I don't know the interval time ? – Haseb Ansari Apr 26 '16 at 21:32
  • @HasebAnsari what do you mean by that?! You have to specify how long it should wait between polls... how can you not know that?! – Morfic Apr 27 '16 at 09:18
  • means I only know that after clickevent some code should run and stop and not in terms of time. – Haseb Ansari Apr 27 '16 at 10:57
  • 1
    @HasebAnsari That sounds like a basic click-listener but there little information to go by. If you have a specific scenario, please create a new question with more details regarding what's going wrong and we'll se what we can do about it. – Morfic Apr 27 '16 at 11:02