public abstract class AbstractView extends java.lang.Object implements View, BeanNameAware, ApplicationContextAware
View
implementations.Modifier and Type | Field and Description |
---|---|
private ApplicationContext |
applicationContext |
private java.lang.String |
beanName |
private java.nio.charset.Charset |
defaultCharset |
protected Log |
logger
Logger that is available to subclasses.
|
private java.util.List<MediaType> |
mediaTypes |
private static java.lang.Object |
NO_VALUE |
private ReactiveAdapterRegistry |
reactiveAdapterRegistry |
static java.lang.String |
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
Well-known name for the RequestDataValueProcessor in the bean factory.
|
private java.lang.String |
requestContextAttribute |
Constructor and Description |
---|
AbstractView() |
AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) |
Modifier and Type | Method and Description |
---|---|
protected RequestContext |
createRequestContext(ServerWebExchange exchange,
java.util.Map<java.lang.String,java.lang.Object> model)
Create a RequestContext to expose under the specified attribute name.
|
protected java.lang.String |
formatViewName() |
ApplicationContext |
getApplicationContext() |
java.lang.String |
getBeanName()
Return the view's name.
|
java.nio.charset.Charset |
getDefaultCharset()
Return the default charset, used when the
content type does not contain one.
|
protected <any> |
getModelAttributes(java.util.Map<java.lang.String,?> model,
ServerWebExchange exchange)
Prepare the model to use for rendering.
|
java.lang.String |
getRequestContextAttribute()
Return the name of the RequestContext attribute, if any.
|
protected RequestDataValueProcessor |
getRequestDataValueProcessor()
Return the
RequestDataValueProcessor to use. |
java.util.List<MediaType> |
getSupportedMediaTypes()
Return the configured media types supported by this view.
|
protected ApplicationContext |
obtainApplicationContext()
Obtain the ApplicationContext for actual use.
|
<any> |
render(java.util.Map<java.lang.String,?> model,
MediaType contentType,
ServerWebExchange exchange)
Prepare the model to render.
|
protected abstract <any> |
renderInternal(java.util.Map<java.lang.String,java.lang.Object> renderAttributes,
MediaType contentType,
ServerWebExchange exchange)
Subclasses must implement this method to actually render the view.
|
protected <any> |
resolveAsyncAttributes(java.util.Map<java.lang.String,java.lang.Object> model)
By default, resolve async attributes supported by the
ReactiveAdapterRegistry to their blocking counterparts. |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setBeanName(java.lang.String beanName)
Set the view's name.
|
void |
setDefaultCharset(java.nio.charset.Charset defaultCharset)
Set the default charset for this view, used when the
content type does not contain one.
|
void |
setRequestContextAttribute(java.lang.String requestContextAttribute)
Set the name of the RequestContext attribute for this view.
|
void |
setSupportedMediaTypes(java.util.List<MediaType> supportedMediaTypes)
Set the supported media types for this view.
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isRedirectView
public static final java.lang.String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
protected final Log logger
private static final java.lang.Object NO_VALUE
private final ReactiveAdapterRegistry reactiveAdapterRegistry
private final java.util.List<MediaType> mediaTypes
private java.nio.charset.Charset defaultCharset
@Nullable private java.lang.String requestContextAttribute
@Nullable private java.lang.String beanName
@Nullable private ApplicationContext applicationContext
public AbstractView()
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry)
public void setSupportedMediaTypes(java.util.List<MediaType> supportedMediaTypes)
public java.util.List<MediaType> getSupportedMediaTypes()
getSupportedMediaTypes
in interface View
public void setDefaultCharset(java.nio.charset.Charset defaultCharset)
public java.nio.charset.Charset getDefaultCharset()
public void setRequestContextAttribute(@Nullable java.lang.String requestContextAttribute)
@Nullable public java.lang.String getRequestContextAttribute()
public void setBeanName(@Nullable java.lang.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 java.lang.String getBeanName()
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()
null
)java.lang.IllegalStateException
- in case of no ApplicationContext setpublic <any> render(@Nullable java.util.Map<java.lang.String,?> model, @Nullable MediaType contentType, ServerWebExchange exchange)
render
in interface View
model
- a Map with name Strings as keys and corresponding model
objects as values (Map can also be null
in case of empty model)contentType
- the content type selected to render with which should
match one of the supported media types
.exchange
- the current exchangeMono
to represent when and if rendering succeedsprotected <any> getModelAttributes(@Nullable java.util.Map<java.lang.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 <any> resolveAsyncAttributes(java.util.Map<java.lang.String,java.lang.Object> model)
ReactiveAdapterRegistry
to their blocking counterparts.
View implementations capable of taking advantage of reactive types can override this method if needed.
Mono
for the completion of async attributes resolutionprotected RequestContext createRequestContext(ServerWebExchange exchange, java.util.Map<java.lang.String,java.lang.Object> model)
The default implementation creates a standard RequestContext instance for the given request and model. Can be overridden in subclasses for custom instances.
exchange
- current exchangemodel
- combined output Map (never null
),
with dynamic values taking precedence over static attributessetRequestContextAttribute(java.lang.String)
@Nullable protected RequestDataValueProcessor getRequestDataValueProcessor()
RequestDataValueProcessor
to use.
The default implementation looks in the Spring configuration
for a RequestDataValueProcessor
bean with
the name REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
.
protected abstract <any> renderInternal(java.util.Map<java.lang.String,java.lang.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 types
.exchange
- current exchange @return Mono
to represent when
and if rendering succeedspublic java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String formatViewName()