public abstract class AbstractView extends Object implements View, BeanNameAware, ApplicationContextAware
View
implementations.Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger that is available to subclasses.
|
static String |
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
Well-known name for the RequestDataValueProcessor in the bean factory.
|
BINDING_CONTEXT_ATTRIBUTE
Constructor and Description |
---|
AbstractView() |
AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) |
Modifier and Type | Method and Description |
---|---|
protected RequestContext |
createRequestContext(ServerWebExchange exchange,
Map<String,Object> model)
Create a
RequestContext to expose under the
specified attribute name. |
protected String |
formatViewName() |
ApplicationContext |
getApplicationContext() |
String |
getBeanName()
Get the view's name.
|
Charset |
getDefaultCharset()
Get the default charset, used when the
content type does not contain one.
|
protected reactor.core.publisher.Mono<Map<String,Object>> |
getModelAttributes(Map<String,?> model,
ServerWebExchange exchange)
Prepare the model to use for rendering.
|
String |
getRequestContextAttribute()
Get the name of the
RequestContext attribute for this view, if any. |
protected RequestDataValueProcessor |
getRequestDataValueProcessor()
Get the
RequestDataValueProcessor to use. |
List<MediaType> |
getSupportedMediaTypes()
Get the configured media types supported by this view.
|
protected ApplicationContext |
obtainApplicationContext()
Obtain the
ApplicationContext for actual use. |
reactor.core.publisher.Mono<Void> |
render(Map<String,?> model,
MediaType contentType,
ServerWebExchange exchange)
Prepare the model to render.
|
protected abstract reactor.core.publisher.Mono<Void> |
renderInternal(Map<String,Object> renderAttributes,
MediaType contentType,
ServerWebExchange exchange)
Subclasses must implement this method to actually render the view.
|
protected reactor.core.publisher.Mono<Void> |
resolveAsyncAttributes(Map<String,Object> model)
Deprecated.
as of 5.1.8 this method is still invoked but it is a no-op.
Please use
resolveAsyncAttributes(Map, ServerWebExchange)
instead. It is invoked after this one and does the actual work. |
protected reactor.core.publisher.Mono<Void> |
resolveAsyncAttributes(Map<String,Object> model,
ServerWebExchange exchange)
Use the configured
ReactiveAdapterRegistry to adapt asynchronous
attributes to Mono<T> or Mono<List<T>> and then wait to
resolve them into actual values. |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setBeanName(String beanName)
Set the view's name.
|
void |
setDefaultCharset(Charset defaultCharset)
Set the default charset for this view, used when the
content type does not contain one.
|
void |
setRequestContextAttribute(String requestContextAttribute)
Set the name of the
RequestContext attribute for this view. |
void |
setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
Set the supported media types for this view.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isRedirectView
public static final String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
protected final Log logger
public AbstractView()
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry)
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
Default is "text/html;charset=UTF-8"
.
public List<MediaType> getSupportedMediaTypes()
getSupportedMediaTypes
in interface View
public void setDefaultCharset(Charset defaultCharset)
Default is UTF 8.
public Charset getDefaultCharset()
public void setRequestContextAttribute(@Nullable String requestContextAttribute)
RequestContext
attribute for this view.
Default is none (null
).
@Nullable public String getRequestContextAttribute()
RequestContext
attribute for this view, if any.public void setBeanName(@Nullable String beanName)
Framework code must call this when constructing views.
setBeanName
in interface BeanNameAware
beanName
- the name of the bean in the factory.
Note that this name is the actual bean name used in the factory, which may
differ from the originally specified name: in particular for inner bean
names, the actual bean name might have been made unique through appending
"#..." suffixes. Use the BeanFactoryUtils.originalBeanName(String)
method to extract the original bean name (without suffix), if desired.@Nullable public String getBeanName()
Should never be null
if the view was correctly configured.
public void setApplicationContext(@Nullable ApplicationContext applicationContext)
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
@Nullable public ApplicationContext getApplicationContext()
protected final ApplicationContext obtainApplicationContext()
ApplicationContext
for actual use.ApplicationContext
(never null
)IllegalStateException
- if the ApplicationContext cannot be obtainedgetApplicationContext()
public reactor.core.publisher.Mono<Void> render(@Nullable Map<String,?> model, @Nullable MediaType contentType, ServerWebExchange exchange)
render
in interface View
model
- a map with attribute names as keys and corresponding model
objects as values (the map can also be null
in case of an empty model)contentType
- the content type selected to render with, which should
match one of the supported media types
exchange
- the current exchangeMono
that represents when and if rendering succeedsprotected reactor.core.publisher.Mono<Map<String,Object>> getModelAttributes(@Nullable Map<String,?> model, ServerWebExchange exchange)
The default implementation creates a combined output Map that includes model as well as static attributes with the former taking precedence.
protected reactor.core.publisher.Mono<Void> resolveAsyncAttributes(Map<String,Object> model, ServerWebExchange exchange)
ReactiveAdapterRegistry
to adapt asynchronous
attributes to Mono<T>
or Mono<List<T>>
and then wait to
resolve them into actual values. When the returned Mono<Void>
completes, the asynchronous attributes in the model will have been
replaced with their corresponding resolved values.Mono
that completes when the model is ready@Deprecated protected reactor.core.publisher.Mono<Void> resolveAsyncAttributes(Map<String,Object> model)
resolveAsyncAttributes(Map, ServerWebExchange)
instead. It is invoked after this one and does the actual work.ReactiveAdapterRegistry
to adapt asynchronous
attributes to Mono<T>
or Mono<List<T>>
and then wait to
resolve them into actual values. When the returned Mono<Void>
completes, the asynchronous attributes in the model would have been
replaced with their corresponding resolved values.Mono
that completes when the model is readyprotected RequestContext createRequestContext(ServerWebExchange exchange, Map<String,Object> model)
RequestContext
to expose under the
specified attribute name.
The default implementation creates a standard RequestContext
instance for the given exchange and model.
Can be overridden in subclasses to create custom instances.
exchange
- the current exchangemodel
- a combined output Map (never null
), with dynamic values
taking precedence over static attributesRequestContext
instancesetRequestContextAttribute(java.lang.String)
@Nullable protected RequestDataValueProcessor getRequestDataValueProcessor()
RequestDataValueProcessor
to use.
The default implementation looks in the ApplicationContext
for a RequestDataValueProcessor
bean with
the name REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
.
RequestDataValueProcessor
, or null
if there is
none in the application contextprotected abstract reactor.core.publisher.Mono<Void> renderInternal(Map<String,Object> renderAttributes, @Nullable MediaType contentType, ServerWebExchange exchange)
renderAttributes
- combined output Map (never null
),
with dynamic values taking precedence over static attributescontentType
- the content type selected to render with, which should
match one of the supported media typesexchange
- current exchangeMono
that represents when and if rendering succeedsprotected String formatViewName()