Replacing Refresher with HeartbeatHandler

Hi all,

With Vaadin 6, we used the Refresher add-on to tell the Application every 10 seconds to refresh the components (i.e. look up current info in back end to display). We also had some
somewhat complicated logic
so that we could still have normal session timeouts based on user interaction, ignoring the Refresher requests.

Switching to v7.2.7 (I might just move to 7.3), I’d like to use the heartbeat mechanism if possible to update the UI. I see how to set the heartbeat interval and how to tell Vaadin to close inactive sessions. But I haven’t figured out yet where to set a new HeartBeat handler (or access the existing one if that’s the proper way to do it). Can someone point me to the right place for this? Or tell me if what I’m attempting isn’t a proper usage of the heartbeat.

(I’ve seen forum posts that say the Refresher add-on is no longer needed for Vaadin 7, but that have been referring to the Refresher usage as a way to keep sessions alive rather than actually refreshing the UI.)

Thank you,
Bobby

Hi Bobby, the heartbeat requests can’t be used to refresh the UI, but in Vaadin 7.1+ there’s a “refresher” functionality built in. You can set a refresh interval using UI.setPollInterval, or you can use server push to make polling not necessary in the first place. Depending on your deployment environment, polling may be a more reliable method than push, though.

Great, thank you! I saw that in one of my many open tabs, and confused it with the heartbeat. Just so I have it straight, I should/could:

  • keep heartbeat interval to a relatively large time frame (e.g. a minute) since it’s mainly used to let the server know it can gcc unused UI objects.
  • set a poll interval (e.g. 10 or 20 seconds) and use
    addPollListener() to call my old refresh() method.

Does the above sound right? Based on
this discussion
, it looks like polling will keep my session alive indefinitely, which is a problem. Will find out soon enough and then see if I can work around it like we did with the Refresher.

Cheers,
Bobby

Part of me sees that and thinks “challenge accepted!” :slight_smile: