@Push, when to use?

I read documentation about @Push technology, and does not get an idea when to start using it? I use Spring Boot and Vaadin 12. I construct my page via @Route(value=“admin”, layout=MainView.class). I use constructor for building UI layout, and @PostConstruct to load DB data in it (in Grid). Also, I have multiple text fields binded to grids via BeanValidationBinder. Now I want to accept DB changes and send it to Grid (.setItems method). What does it mean, should I use ui.accept() method for this? Should I use ui.accept() from @PostConstruct? I asking all above because it is not clear to me what does it mean “When you need to update a UI from another UI, possibly of another user, or from a background thread running in the server,”—a “background thread running in the server”.

And a companion questions which is not clear to me: if I don’t use @Push annotation, then how UI updates works from event method? Currently I can refresh data in Grid without ui.accept() and without @Push annotation, and it will displays instantly. So, why to use @Push annotation then? And why to use ui.accept(), I mean, why not to use it always, or implement inside the framework on low-level. I think, this approach should be told more detailed, in documentation, or here at forum. Please, if you have time to share your expertise, I’ll appreciate.

Hi,

You need @Push when you want to make modifications to a UI from a thread different to the one that started with an HTTP request.

For example, when a user clicks a button, an HTTP request is sent to the server and a new thread is started. You can make any UI modifications without worring about Push or the UI.access(Command) method at this point. However, if you start a new Thread when the user clicks the button, that thread is deatached from the HTTP request. If you make an update to the UI from that new thread, you won’t see the changes in the browser unless you activate Push with @Push and put the code that changes the UI in a Command passed to the UI.access(Command) method. You can think of these kind of changes as UI changes not started by a user action in the browser but started by the server.

This video shows an example using Vaadin 8:
https://www.youtube.com/watch?v=EG6iizVH1rY

It shouldn’t be too different with Vaadin 10+.

Alejandro, thank you very much. It is now clear to me.

Mikhail Emelchenkov:
Alejandro, thank you very much. It is now clear to me.

Good to hear. Happy coding!

I had @Push working well in Vaadin 8, but having trouble with Vaadin 14. Even the PushyView example found here:
https://vaadin.com/docs/v14/flow/advanced/tutorial-push-access.html
…isn’t working as I expected.

When I run the PushyView, it usually is successful up to “This is Update 3”, and then lags for quite a while before displaying the other 7 updates.

However, if I move the mouse, or click while it is paused, it does indeed start updating. It’s as if the UI has lost focused (perhaps there’s an aggressive timeout parameter somewhere?)

Any thoughts welcome-- I feel if I can get this basic example working I’ll be off and running. Using 14.1.25.

Moreover, the is no way to have working websocket on SpringBoot 2.x, sample projects works only on SpringBoot 1.x.

Any thoughts welcome, maybe somebody was more lucky them me.

Gabe Merton:
I had @Push working well in Vaadin 8, but having trouble with Vaadin 14. Even the PushyView example found here:
https://vaadin.com/docs/v14/flow/advanced/tutorial-push-access.html
…isn’t working as I expected.

When I run the PushyView, it usually is successful up to “This is Update 3”, and then lags for quite a while before displaying the other 7 updates.

However, if I move the mouse, or click while it is paused, it does indeed start updating. It’s as if the UI has lost focused (perhaps there’s an aggressive timeout parameter somewhere?)

Any thoughts welcome-- I feel if I can get this basic example working I’ll be off and running. Using 14.1.25.

I can confirm it happens on Chrome but not on Safari. Can you please open a new issue at https://github.com/vaadin/flow/issues?

Michele Faugiana:
Moreover, the is no way to have working websocket on SpringBoot 2.x, sample projects works only on SpringBoot 1.x.

Any thoughts welcome, maybe somebody was more lucky them me.

It seems to work for me. Cannot reproduce.