VAADIN 7: What is the simplest way to refresh a Vaadin View in 5 minute intervals?
Asked Answered
H

1

2

I'm trying to implement an automatic refresh on a List of components in a Vaadin view. The list gets its contents from a database. I can refresh the list with a button, that is already implemented.

However, I would like to know what is the simplest way to make it so, that this refresh event, that I already have, would automatically refresh in 5 minute (300 000 milliseconds) intervals?

Here's what I tried and it keeps refreshing even after I exit the view so it doesn't really work. I'd like the refresh to happen in 5 minute intervals only while that certain view is being shown.

UI myUI = UI.getCurrent();  

            myUI.setPollInterval(300000);
            myUI.addPollListener(event -> {
                refreshList();
            });

How would I make it so that the refresh doesn't happen after navigating to other views? And is there some simpler way to do this in Vaadin? Thank you

Humiliation answered 27/8, 2015 at 12:28 Comment(1)
#51795118Afrit
T
3

You could do so that you call

myUI.setPollInterval(300000);

when the view is activated, and you disable it by calling

myUI.setPollInterval(-1);

when another view is activated. If you use Vaadin Navigator, then you could use ViewChangeListener for handling the polling.

Trimmer answered 27/8, 2015 at 18:32 Comment(3)
Thank you, I'll try that tomorrow and come back to your answer. We are using Vaadin Navigator.Humiliation
Does setPollInterval() work globally or locally? Does setPollInterval set this for all session?Dung
@Dung per connector object.Afrit

© 2022 - 2024 — McMap. All rights reserved.