Reputation: 471
In my application (Vaadin.8.6.3, Tomcat 9 and Maven 3) I need to set cookies which works well unless I use @Push. I need @Push only for one progress window implemented as described here.
I read that it is possible to turn @Push on and off using e.g.
getUI().getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
I tried several ways and places in the code to turn @Push on and off, but nothing worked.
One example:
@Push(PushMode.DISABLED)
public class MyUI extends UI {
Since I have more than one place in the code where I do cookies handling, I thought the best is to disable @Push in the UI class and turn it on when I run the background thread.
With a button click I start the runnable and in the runnable I turn on the @Push mode:
class Loader implements Runnable {
@Override
public void run() {
try {
getUI().access(() -> {
getUI().getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
getUI().getNavigator().navigateTo("scandataview/" + name);
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have no error but nothing happens, i.e. the data I want to load are never loaded and the progress window stays forever.
My questions:
Is it possible to just turn on @Push to show the progress window while loading long data and turn it off after loading?
If yes, where in the code should I turn on/off the @Push?
If you need more information please let me know. I would be very glad for your help. Thank you!
Upvotes: 0
Views: 358
Reputation: 10643
If you need Push only in one place and for some reason have described complications I recommend the following.
Set the push mode to manual i.e. @Push(PushMode.MANUAL)
And then modify the code as follows, i.e. perform manual push instead of relying automatic.
class Loader implements Runnable {
@Override
public void run() {
try {
getUI().access(() -> {
getUI().getNavigator().navigateTo("scandataview/" + name);
getUI().push();
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
The above use of access()
can be further improved according information provided in this question: Access method from current UI in Vaadin
Upvotes: 1