public class ThymeleafReactiveViewResolver
extends org.springframework.web.reactive.result.view.ViewResolverSupport
implements org.springframework.web.reactive.result.view.ViewResolver
Implementation of the Spring WebFlux ViewResolver
interface.
View resolvers execute after the controller ends its execution. They receive the name
of the view to be processed and are in charge of creating (and configuring) the
corresponding View
object for it.
The View
implementations managed by this class are of type ThymeleafReactiveView
.
ThymeleafReactiveView
,
ISpringWebFluxTemplateEngine
Modifier and Type | Field and Description |
---|---|
static String |
FORWARD_URL_PREFIX |
static String |
REDIRECT_URL_PREFIX
Prefix to be used in view names (returned by controllers) for specifying an
HTTP redirect.
|
Constructor and Description |
---|
ThymeleafReactiveViewResolver()
Create an instance of ThymeleafReactiveViewResolver.
|
Modifier and Type | Method and Description |
---|---|
void |
addStaticVariable(String name,
Object value)
Add a new static variable.
|
protected boolean |
canHandle(String viewName,
Locale locale) |
boolean |
getAlwaysProcessRedirectAndForward()
Return whether this view resolver should always process forwards and redirects independently of the value of
the viewNames property.
|
String[] |
getExcludedViewNames() |
int |
getOrder()
Returns the order in which this view resolver will be queried.
|
Function<String,org.springframework.web.reactive.result.view.RedirectView> |
getRedirectViewProvider()
Returns the provider function for creating
RedirectView instances when a redirect
request is passed to the view resolver. |
int |
getResponseMaxChunkSizeBytes()
Return the maximum size (in bytes) allowed for the chunks
(
DataBuffer ) that are produced by the Thymeleaf engine and passed
to the server as output. |
Map<String,Object> |
getStaticVariables()
Return the static variables, which will be available at the context
every time a view resolved by this ViewResolver is processed.
|
ISpringWebFluxTemplateEngine |
getTemplateEngine()
Returns the Thymeleaf template engine instance
(implementation of
ISpringWebFluxTemplateEngine to be used for the
execution of templates. |
protected Class<? extends ThymeleafReactiveView> |
getViewClass() |
String[] |
getViewNames() |
protected reactor.core.publisher.Mono<org.springframework.web.reactive.result.view.View> |
loadView(String viewName,
Locale locale) |
reactor.core.publisher.Mono<org.springframework.web.reactive.result.view.View> |
resolveViewName(String viewName,
Locale locale) |
void |
setAlwaysProcessRedirectAndForward(boolean alwaysProcessRedirectAndForward)
Set whether this view resolver should always process forwards and redirects independently of the value of
the viewNames property.
|
void |
setExcludedViewNames(String[] excludedViewNames) |
void |
setOrder(int order)
Specify the order in which this view resolver will be queried.
|
void |
setRedirectViewProvider(Function<String,org.springframework.web.reactive.result.view.RedirectView> redirectViewProvider)
Sets the provider function for creating
RedirectView instances when a redirect
request is passed to the view resolver. |
void |
setResponseMaxChunkSizeBytes(int responseMaxChunkSizeBytes)
Set the maximum size (in bytes) allowed for the chunks (
DataBuffer )
that are produced by the Thymeleaf engine and passed to the server as output. |
void |
setStaticVariables(Map<String,?> variables)
Sets a set of static variables, which will be available at the context
every time a view resolved by this ViewResolver is processed.
|
void |
setTemplateEngine(ISpringWebFluxTemplateEngine templateEngine)
Set the template engine object (implementation of
ISpringWebFluxTemplateEngine to be
used for processing templates. |
void |
setViewClass(Class<? extends ThymeleafReactiveView> viewClass)
Set the view class that should be used to create views.
|
void |
setViewNames(String[] viewNames) |
public static final String REDIRECT_URL_PREFIX
Prefix to be used in view names (returned by controllers) for specifying an HTTP redirect.
Value: redirect:
public static final String FORWARD_URL_PREFIX
public ThymeleafReactiveViewResolver()
Create an instance of ThymeleafReactiveViewResolver.
public void setViewClass(Class<? extends ThymeleafReactiveView> viewClass)
Set the view class that should be used to create views. This must be a subclass
of ThymeleafReactiveView
.
viewClass
- class that is assignable to the required view class
(by default, ThymeleafReactiveView).protected Class<? extends ThymeleafReactiveView> getViewClass()
public ISpringWebFluxTemplateEngine getTemplateEngine()
Returns the Thymeleaf template engine instance
(implementation of ISpringWebFluxTemplateEngine
to be used for the
execution of templates.
public void setTemplateEngine(ISpringWebFluxTemplateEngine templateEngine)
Set the template engine object (implementation of ISpringWebFluxTemplateEngine
to be
used for processing templates.
templateEngine
- the template engine.public Map<String,Object> getStaticVariables()
Return the static variables, which will be available at the context every time a view resolved by this ViewResolver is processed.
These static variables are added to the context by the view resolver before every view is processed, so that they can be referenced from the context like any other context variables, for example: ${myStaticVar}.
public void addStaticVariable(String name, Object value)
Add a new static variable.
These static variables are added to the context by the view resolver before every view is processed, so that they can be referenced from the context like any other context variables, for example: ${myStaticVar}.
name
- the name of the static variablevalue
- the value of the static variablepublic void setStaticVariables(Map<String,?> variables)
Sets a set of static variables, which will be available at the context every time a view resolved by this ViewResolver is processed.
This method does not overwrite the existing static variables, it simply adds the ones specify to any variables already registered.
These static variables are added to the context by the view resolver before every view is processed, so that they can be referenced from the context like any other context variables, for example: ${myStaticVar}.
variables
- the set of variables to be added.public void setOrder(int order)
Specify the order in which this view resolver will be queried.
Spring Web applications can have several view resolvers configured, and this order property established the order in which they will be queried for view resolution.
setOrder
in class org.springframework.web.reactive.result.view.ViewResolverSupport
order
- the order in which this view resolver will be asked to resolve
the view.public int getOrder()
Returns the order in which this view resolver will be queried.
Spring Web applications can have several view resolvers configured, and this order property established the order in which they will be queried for view resolution.
getOrder
in interface org.springframework.core.Ordered
getOrder
in class org.springframework.web.reactive.result.view.ViewResolverSupport
public void setRedirectViewProvider(Function<String,org.springframework.web.reactive.result.view.RedirectView> redirectViewProvider)
Sets the provider function for creating RedirectView
instances when a redirect
request is passed to the view resolver.
Note the parameter specified to the function will be the URL of the redirect (as specified in the view name returned by the controller, without the redirect: prefix).
redirectViewProvider
- the redirect-view provider function.public Function<String,org.springframework.web.reactive.result.view.RedirectView> getRedirectViewProvider()
Returns the provider function for creating RedirectView
instances when a redirect
request is passed to the view resolver.
Note the parameter specified to the function will be the URL of the redirect (as specified in the view name returned by the controller, without the redirect: prefix).
public void setAlwaysProcessRedirectAndForward(boolean alwaysProcessRedirectAndForward)
Set whether this view resolver should always process forwards and redirects independently of the value of the viewNames property.
When this flag is set to true (default value), any view name that starts with the redirect: or forward: prefixes will be resolved by this ViewResolver even if the view names would not match what is established at the viewNames property.
Note that the behaviour of resolving view names with these prefixes is exactly the same with this flag set to true or false (perform an HTTP redirect or forward to an internal resource). The only difference is whether the prefixes have to be explicitly specified at viewNames or not.
Default value is true.
alwaysProcessRedirectAndForward
- true if redirects and forwards are always processed, false if this will
depend on what is established at the viewNames property.public boolean getAlwaysProcessRedirectAndForward()
Return whether this view resolver should always process forwards and redirects independently of the value of the viewNames property.
When this flag is set to true (default value), any view name that starts with the redirect: or forward: prefixes will be resolved by this ViewResolver even if the view names would not match what is established at the viewNames property.
Note that the behaviour of resolving view names with these prefixes is exactly the same with this flag set to true or false (perform an HTTP redirect or forward to an internal resource). The only difference is whether the prefixes have to be explicitly specified at viewNames or not.
Default value is true.
public void setResponseMaxChunkSizeBytes(int responseMaxChunkSizeBytes)
Set the maximum size (in bytes) allowed for the chunks (DataBuffer
)
that are produced by the Thymeleaf engine and passed to the server as output.
In Spring WebFlux applications, Thymeleaf has three modes of operation depending on whether a limit has been set for the output chunk size and/or data-driver context variables have been specified:
DataBuffer
.IReactiveDataDriverContextVariable
). This
variable is expected to contain a data stream (usually in the shape of a
Publisher
that Thymeleaf will consume, creating markup output as data
is streamed from this data-driver and letting the output channels of the server throttle
template engine execution by means of back-pressure. Additionally, depending on whether a value has
been specified for this property or not, Thymeleaf will never generate
DataBuffer
output chunks larger than the specified size,
and will request the server to perform an output flush operation after each chunk is produced.If this property is set to -1 or Integer.MAX_VALUE, no size limit will be used. Note also that there is no limit set by default.
Also note that this parameter will be ignored when returning SSE (Server-Sent Events), as buffer size in such case will adapt to the size of each returned element (plus its SSE metadata).
responseMaxChunkSizeBytes
- the maximum size in bytes for output chunks
(DataBuffer
objects), or
-1 or Integer.MAX_VALUE if no limit is to be used.public int getResponseMaxChunkSizeBytes()
Return the maximum size (in bytes) allowed for the chunks
(DataBuffer
) that are produced by the Thymeleaf engine and passed
to the server as output.
In Spring WebFlux applications, Thymeleaf has three modes of operation depending on whether a limit has been set for the output chunk size and/or data-driver context variables have been specified:
DataBuffer
.IReactiveDataDriverContextVariable
). This
variable is expected to contain a data stream (usually in the shape of a
Publisher
that Thymeleaf will consume, creating markup output as data
is streamed from this data-driver and letting the output channels of the server throttle
template engine execution by means of back-pressure. Additionally, depending on whether a value has
been specified for this property or not, Thymeleaf will never generate
DataBuffer
output chunks larger than the specified size,
and will request the server to perform an output flush operation after each chunk is produced.If this property is set to -1 or Integer.MAX_VALUE, no size limit will be used. Note also that there is no limit set by default.
Also note that this parameter will be ignored when returning SSE (Server-Sent Events), as buffer size in such case will adapt to the size of each returned element (plus its SSE metadata).
DataBuffer
objects), or
-1 or Integer.MAX_VALUE if no limit is to be used.public void setViewNames(String[] viewNames)
public String[] getViewNames()
public void setExcludedViewNames(String[] excludedViewNames)
public String[] getExcludedViewNames()
public reactor.core.publisher.Mono<org.springframework.web.reactive.result.view.View> resolveViewName(String viewName, Locale locale)
resolveViewName
in interface org.springframework.web.reactive.result.view.ViewResolver
Copyright © 2017 The THYMELEAF team. All rights reserved.