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: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java
+1
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,7 @@ public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler,
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+48
Original file line number
Diff line number
Diff line change
@@ -3032,6 +3032,54 @@ Spring Boot includes auto-configuration support for the following templating eng
3032
3032
When you use one of these templating engines with the default configuration, your
3033
3033
templates are picked up automatically from `src/main/resources/templates`.
3034
3034
3035
+
==== Mustache Views
3036
+
3037
+
There are some special features of the `MustacheView` that make it suitable for handling the rendering of reactive elements. Most browsers will start to show content before the HTML tags are closed, so you can drip feed a list or a table into the view as the content becomes available.
3038
+
3039
+
===== Progressive Rendering
3040
+
3041
+
A model element of type `Publisher` will be left in the model (instead of expanding it before the view is rendered), if its name starts with "flux" or "mono" or "publisher". The `View` is then rendered and flushed to the HTTP response as soon as each element is published. Browsers are really good at rendering partially complete HTML, so the flux elements will most likely be visible to the user as soon as they are available. This is useful for rendering the "main" content of a page if it is a list or a table, for instance.
3042
+
3043
+
===== Sserver Sent Event (SSE) Support
3044
+
3045
+
To render a `View` with content type `text/event-stream` you need a model element of type `Publisher`, and also a template that includes that element (probably starts and ends with it). There is a convenience Lambda (`ssedata`) added to the model for you that prepends every line with `data:` - you can use it if you wish to simplify the rendering of the data elements. Two new lines are added after each item in `{{#ssedata}}`. E.g. with an element called `flux.events` of type `Flux<Event>`:
3046
+
3047
+
```
3048
+
{{#flux.events}}
3049
+
event: message
3050
+
id: {{id}}
3051
+
{{#ssedata}}
3052
+
<div>
3053
+
<span>Name: {{name}}<span>
3054
+
<span>Value: {{value}}<span>
3055
+
</div>
3056
+
{{/ssedata}}
3057
+
{{/flux.events}}
3058
+
```
3059
+
3060
+
the output will be
3061
+
3062
+
```
3063
+
event: message
3064
+
id: 0
3065
+
data: <div>
3066
+
data: <span>Name: foo<span>
3067
+
data: <span>Value: bar<span>
3068
+
data: </div>
3069
+
3070
+
3071
+
event: message
3072
+
id: 1
3073
+
data: <div>
3074
+
data: <span>Name: spam<span>
3075
+
data: <span>Value: bucket<span>
3076
+
data: </div>
3077
+
3078
+
3079
+
... etc.
3080
+
```
3081
+
3082
+
assuming the `Event` object has fields `id`, `name`, `value`.
0 commit comments