Top Description Fields Constructors Methods
org.springframework.web.reactive.result.view

public abstract Class AbstractView

extends Object
implements View, BeanNameAware, ApplicationContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.web.reactive.result.view.View
Known Direct Subclasses
org.springframework.web.reactive.result.view.AbstractUrlBasedView
Imports
java.nio.charset.Charset, .StandardCharsets, java.util.ArrayList, .Collection, .Collections, .List, .Map, java.util.concurrent.ConcurrentHashMap, org.apache.commons.logging.Log, .LogFactory, reactor.core.publisher.Flux, .Mono, org.springframework.beans.BeanUtils, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContext, .ApplicationContextAware, org.springframework.core.ReactiveAdapter, .ReactiveAdapterRegistry, org.springframework.http.MediaType, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.validation.BindingResult, org.springframework.web.reactive.BindingContext, org.springframework.web.server.ServerWebExchange

Base class for View implementations.
Authors
Rossen Stoyanchev, Sam Brannen
Since
5.0

Field Summary

Modifier and TypeField and Description
private final ReactiveAdapterRegistry
private ApplicationContext
private String
private Charset
protected final Log
logger

Logger that is available to subclasses.

private final List<MediaType>
public static final String
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME

Well-known name for the RequestDataValueProcessor in the bean factory.

private String

Constructor Summary

AccessConstructor and Description
public
public
AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry)

Method Summary

Modifier and TypeMethod and Description
private void
protected RequestContext

Returns:

the RequestContext instance
createRequestContext
(ServerWebExchange
the current exchange
exchange
,
Map<String, Object>
a combined output Map (never null), with dynamic values taking precedence over static attributes
model
)

Create a RequestContext to expose under the specified attribute name.

protected String
public ApplicationContext
public String
getBeanName()

Get the view's name.

public Charset
getDefaultCharset()

Get the default charset, used when the content type does not contain one.

protected Mono<Map<String, Object>>
getModelAttributes(Map<String, ?> model, ServerWebExchange exchange)

Prepare the model to use for rendering.

public String
getRequestContextAttribute()

Get the name of the RequestContext attribute for this view, if any.

protected RequestDataValueProcessor

Returns:

the RequestDataValueProcessor, or null if there is none in the application context
getRequestDataValueProcessor
()

Get the RequestDataValueProcessor to use.

public List<MediaType>
getSupportedMediaTypes()

Overrides default org.springframework.web.reactive.result.view.View.getSupportedMediaTypes.

Get the configured media types supported by this view.

protected final ApplicationContext

Returns:

the ApplicationContext (never null)
obtainApplicationContext
()

Obtain the ApplicationContext for actual use.

public Mono<Void>

Returns:

a Mono that represents when and if rendering succeeds
render
(Map<String, ?>
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)
model
,
MediaType
the content type selected to render with, which should match one of the supported media types
contentType
,
ServerWebExchange
the current exchange
exchange
)

Implements org.springframework.web.reactive.result.view.View.render.

Prepare the model to render.

protected abstract Mono<Void>

Returns:

a Mono that represents when and if rendering succeeds
renderInternal
(Map<String, Object>
combined output Map (never null), with dynamic values taking precedence over static attributes
renderAttributes
,
MediaType
the content type selected to render with, which should match one of the supported media types
contentType
,
ServerWebExchange
current exchange
exchange
)

Subclasses must implement this method to actually render the view.

protected Mono<Void>

Returns:

result a Mono that completes when the model is ready
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.

public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
applicationContext
)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

public void
setBeanName(String
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.
beanName
)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Set the view's name.

public void
setDefaultCharset(Charset defaultCharset)

Set the default charset for this view, used when the content type does not contain one.

public void
setRequestContextAttribute(String requestContextAttribute)

Set the name of the RequestContext attribute for this view.

public void
setSupportedMediaTypes(List<MediaType> supportedMediaTypes)

Set the supported media types for this view.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

adapterRegistryback to summary
private final ReactiveAdapterRegistry adapterRegistry
applicationContextback to summary
private ApplicationContext applicationContext
Annotations
@Nullable
beanNameback to summary
private String beanName
Annotations
@Nullable
defaultCharsetback to summary
private Charset defaultCharset
loggerback to summary
protected final Log logger

Logger that is available to subclasses.

mediaTypesback to summary
private final List<MediaType> mediaTypes
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAMEback to summary
public static final String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME

Well-known name for the RequestDataValueProcessor in the bean factory.

requestContextAttributeback to summary
private String requestContextAttribute
Annotations
@Nullable

Constructor Detail

AbstractViewback to summary
public AbstractView()
AbstractViewback to summary
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry)

Method Detail

addBindingResultback to summary
private void addBindingResult(String name, Object value, Map<String, Object> model, ServerWebExchange exchange)
createRequestContextback to summary
protected RequestContext createRequestContext(ServerWebExchange exchange, Map<String, Object> model)

Create a 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.

Parameters
exchange:ServerWebExchange

the current exchange

model:Map<String, Object>

a combined output Map (never null), with dynamic values taking precedence over static attributes

Returns:RequestContext

the RequestContext instance

See Also
setRequestContextAttribute
formatViewNameback to summary
protected String formatViewName()
getApplicationContextback to summary
public ApplicationContext getApplicationContext()
Annotations
@Nullable
getBeanNameback to summary
public String getBeanName()

Get the view's name.

Should never be null if the view was correctly configured.

Annotations
@Nullable
getDefaultCharsetback to summary
public Charset getDefaultCharset()

Get the default charset, used when the content type does not contain one.

getModelAttributesback to summary
protected Mono<Map<String, Object>> getModelAttributes(Map<String, ?> model, ServerWebExchange exchange)

Prepare the model to use for rendering.

The default implementation creates a combined output Map that includes model as well as static attributes with the former taking precedence.

getRequestContextAttributeback to summary
public String getRequestContextAttribute()

Get the name of the RequestContext attribute for this view, if any.

Annotations
@Nullable
getRequestDataValueProcessorback to summary
protected RequestDataValueProcessor getRequestDataValueProcessor()

Get the RequestDataValueProcessor to use.

The default implementation looks in the ApplicationContext for a RequestDataValueProcessor bean with the name REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME.

Returns:RequestDataValueProcessor

the RequestDataValueProcessor, or null if there is none in the application context

Annotations
@Nullable
getSupportedMediaTypesback to summary
public List<MediaType> getSupportedMediaTypes()

Overrides default org.springframework.web.reactive.result.view.View.getSupportedMediaTypes.

Get the configured media types supported by this view.

Annotations
@Override
obtainApplicationContextback to summary
protected final ApplicationContext obtainApplicationContext()

Obtain the ApplicationContext for actual use.

Returns:ApplicationContext

the ApplicationContext (never null)

Exceptions
IllegalStateException:
if the ApplicationContext cannot be obtained
See Also
getApplicationContext()
renderback to summary
public Mono<Void> render(Map<String, ?> model, MediaType contentType, ServerWebExchange exchange)

Implements org.springframework.web.reactive.result.view.View.render.

Prepare the model to render.

Parameters
model:Map<String, ?>

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:MediaType

the content type selected to render with, which should match one of the supported media types

exchange:ServerWebExchange

the current exchange

Returns:Mono<Void>

a Mono that represents when and if rendering succeeds

Annotations
@Override
renderInternalback to summary
protected abstract Mono<Void> renderInternal(Map<String, Object> renderAttributes, MediaType contentType, ServerWebExchange exchange)

Subclasses must implement this method to actually render the view.

Parameters
renderAttributes:Map<String, Object>

combined output Map (never null), with dynamic values taking precedence over static attributes

contentType:MediaType

the content type selected to render with, which should match one of the supported media types

exchange:ServerWebExchange

current exchange

Returns:Mono<Void>

a Mono that represents when and if rendering succeeds

resolveAsyncAttributesback to summary
protected 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. When the returned Mono<Void> completes, the asynchronous attributes in the model will have been replaced with their corresponding resolved values.

Returns:Mono<Void>

result a Mono that completes when the model is ready

Since
5.1.8
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Doc from org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
applicationContext:ApplicationContext

the ApplicationContext object to be used by this object

Annotations
@Override
setBeanNameback to summary
public void setBeanName(String beanName)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Set the view's name. Helpful for traceability.

Framework code must call this when constructing views.

Parameters
beanName:String

Doc from org.springframework.beans.factory.BeanNameAware.setBeanName.

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.

Annotations
@Override
setDefaultCharsetback to summary
public void setDefaultCharset(Charset defaultCharset)

Set the default charset for this view, used when the content type does not contain one.

Default is UTF 8.

setRequestContextAttributeback to summary
public void setRequestContextAttribute(String requestContextAttribute)

Set the name of the RequestContext attribute for this view.

Default is none (null).

setSupportedMediaTypesback to summary
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes)

Set the supported media types for this view.

Default is "text/html;charset=UTF-8".

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override