You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/building-apps/server-push/callbacks.adoc
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,20 +2,19 @@
2
2
title: Callbacks
3
3
page-title: How to use server push with callbacks | Vaadin
4
4
description: How to use server push with callbacks.
5
-
meta-description: Learn how to use server push with callbacks when building the UI layer of your Vaadin application.
5
+
meta-description: Learn how to use server push with callbacks when building the UI layer of your Vaadin application.
6
6
order: 20
7
-
section-nav: badge-flow
8
7
---
9
8
10
9
11
-
= Implementing Callbacks [badge-flow]#Flow#
10
+
= Implementing Callbacks
12
11
13
12
When building the user interface with Vaadin Flow, the easiest way of allowing a background job to update the user interface is through callbacks. This is explained in more detail in the <</building-apps/business-logic/background-jobs/interaction/callbacks#,Callbacks>> documentation page.
14
13
15
-
Whenever you implement a callback, you have remember that the callback is called by the background thread. This means that any updates to the user interface must happen inside a call to `UI.access()`.
14
+
Whenever you implement a callback, remember that the callback is called by the background thread. This means that any updates to the user interface must happen inside a call to `UI.access()`.
16
15
17
16
[NOTE]
18
-
The examples on this page only work with push enabled. For information about how to do that, see the <<.#enabling-push-flow,Server Push>> documentation page.
17
+
The examples on this page only work with push enabled. For information about how to do that, see the <<index.adoc#,Server Push>> documentation page.
19
18
20
19
For every callback, you should create a private method in your user interface. The method is called inside `UI.access()`, so you can safely update the user interface inside it.
Copy file name to clipboardExpand all lines: articles/building-apps/server-push/futures.adoc
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,13 @@
1
1
---
2
2
title: Futures
3
-
page-title: How to use server push with CompletableFuture | Vaadin
3
+
page-title: How to use server push with CompletableFuture | Vaadin
4
4
description: How to use server push with CompletableFuture.
5
5
meta-description: Learn how to use server push with CompletableFuture when building the UI layer of your Vaadin application.
6
6
order: 30
7
-
section-nav: badge-flow
8
7
---
9
8
10
9
11
-
= Consuming Futures [badge-flow]#Flow#
10
+
= Consuming Futures
12
11
13
12
Some background jobs may use `CompletableFuture` to inform the user interface of results and errors. This is covered in the <</building-apps/business-logic/background-jobs/interaction/futures#,Returning Futures>> documentation page.
Copy file name to clipboardExpand all lines: articles/building-apps/server-push/index.adoc
+17-3Lines changed: 17 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ In Hilla views, push is always enabled when you subscribe to a _reactive endpoin
19
19
Server push is not the same as Web Push, which is also supported by Vaadin Flow. For more information, see the <<{articles}/flow/configuration/webpush#,Web Push Notifications>> documentation page.
20
20
21
21
22
-
== Enabling Push [badge-flow]#Flow#
22
+
== Enabling Push
23
23
24
24
Before you can use server push in Flow, you have to enable it. You do this by adding the `@Push` annotation to the application shell class, like this:
25
25
@@ -40,9 +40,23 @@ public class Application implements AppShellConfigurator {
40
40
}
41
41
----
42
42
43
-
// TODO Add link to page about the application shell, once is has been written (currently, the contents is scattered all over the documentation)
44
43
45
-
// TODO Transport modes? Or is that something for the reference material.
44
+
== Push Modes
45
+
46
+
By default, Flow uses automatic pushing (`PushMode.AUTOMATIC`). This means that any pending changes are pushed to the browser after `UI.access()` finishes. This is the recommended mode for most applications.
47
+
48
+
You can also configure Flow to use manual pushing (`PushMode.MANUAL`). With manual mode, you call `UI.push()` explicitly to send changes to the browser. This gives you more control over when changes are pushed, which is useful when you want to batch multiple updates together.
49
+
50
+
For details on how to use `UI.access()` and `UI.push()`, see <<updates#,Pushing UI Updates>>.
51
+
52
+
53
+
== Transport Options
54
+
55
+
Server push can use several transports: WebSockets, long polling, or combined WebSockets+XHR. The default is WebSockets+XHR, which works well in most environments.
56
+
57
+
You might need to change the transport if you're experiencing connectivity issues, for example when running behind certain proxies or corporate firewalls that block WebSocket connections. In such cases, long polling can be a more reliable alternative.
58
+
59
+
For technical details about configuring transports, see <<{articles}/flow/advanced/server-push#,Server Push Configuration>>.
Copy file name to clipboardExpand all lines: articles/building-apps/server-push/reactive.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ order: 40
9
9
10
10
When building the user interface with either Vaadin Flow or Hilla, you can use reactive streams to allow a background job to update the user interface. This is covered in the <</building-apps/business-logic/background-jobs/interaction/reactive#,Producing Reactive Streams>> documentation page.
11
11
12
-
//RUSSELL: This opening paragraph gives the feeling that the reader shouldn't read this page since it immediately sends them elsewhere. You need a sentence or two that says the point of continuing, maybe something about subscribing, handling errors, etc.
12
+
This page covers subscribing to reactive streams, handling errors, and buffering high-frequency updates.
Copy file name to clipboardExpand all lines: articles/building-apps/server-push/threads.adoc
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,10 @@ page-title: How to use threads in a Vaadin Flow user interface
4
4
description: How to use threads in a Vaadin Flow user interface.
5
5
meta-description: Learn how to use use virtual threads in a Vaadin Flow user interface by reading this guide.
6
6
order: 10
7
-
section-nav: badge-flow
8
7
---
9
8
10
9
11
-
= User Interface Threads [badge-flow]#Flow#
10
+
= User Interface Threads
12
11
13
12
Developers often use server push to update the user interface from background jobs (see <</building-apps/business-logic/background-jobs/interaction#,Background Jobs - UI Interaction>>). However, in Vaadin Flow, there are also cases where you may want to start a separate thread for use by the user interface itself. You might, for instance, want to show the server date and time in "real time".
14
13
@@ -17,7 +16,7 @@ If you have experience with Swing, you might be tempted to use a `Timer`, or to
17
16
As a better strategy, use virtual threads, or Spring's `TaskExecutor` and `TaskScheduler`. These are explained in the following sections, with some examples.
18
17
19
18
[NOTE]
20
-
The examples on this page only work with push enabled. For information about how to do that, see the <<.#enabling-push-flow,Server Push>> documentation page.
19
+
The examples on this page only work with push enabled. For information about how to do that, see the <<index.adoc#,Server Push>> documentation page.
Copy file name to clipboardExpand all lines: articles/building-apps/server-push/updates.adoc
+2-7Lines changed: 2 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,10 @@ page-title: How to push updates to a Vaadin Flow user interface
4
4
description: How to push updates to a Vaadin Flow user interface.
5
5
meta-description: Learn how to push updates to a Vaadin Flow user interface by reading this guide.
6
6
order: 1
7
-
section-nav: badge-flow
8
7
---
9
8
10
9
11
-
= Pushing UI Updates [badge-flow]#Flow#
10
+
= Pushing UI Updates
12
11
13
12
Whenever you're using server push in Vaadin Flow, you're triggering it from a thread other than the normal HTTP request thread. Making changes to a UI from another thread and pushing them to the browser requires locking the user session. Otherwise, the UI update performed from another thread could conflict with a regular event-driven update and cause either data corruption, race conditions or deadlocks.
14
13
@@ -22,7 +21,7 @@ ui.access(() -> {
22
21
----
23
22
24
23
[NOTE]
25
-
The examples on this page only work with push enabled. For information about how to do that, see the <<.#enabling-push-flow,Server Push>> documentation page.
24
+
The examples on this page only work with push enabled. For information about how to do that, see the <<index.adoc#,Server Push>> documentation page.
26
25
27
26
By default, Flow uses automatic pushing. This means that any pending changes are pushed to the browser after the command passed to `UI.access()` finishes. You can also configure Flow to use manual pushing. This would give you more control over when changes are pushed to the browser. For example, you can push multiple times inside a single call to `UI.access()`.
28
27
@@ -49,8 +48,6 @@ ui.access(() -> {
49
48
50
49
== Getting the UI Instance
51
50
52
-
// This assumes that the UI has been explained earlier, and what attach and detach means.
53
-
54
51
Before you can call `access()`, you need to get the `UI` instance. You'd typically use `Component.getUI()` or `UI.getCurrent()` for this. However, both are problematic when it comes to server push.
55
52
56
53
`Component.getUI()` is not thread-safe, which means you should only call it while the user session is locked. Therefore, you can't use it to call `access()`.
@@ -200,5 +197,3 @@ if (ui.getSession().hasLock()) {
200
197
});
201
198
}
202
199
----
203
-
204
-
// TODO Consider showing an example of a UIRunner that takes a Runnable or Consumer, performs the check, and calls it directly or inside UI.access().
0 commit comments