org.springframework.web.reactive.result.view

Class AbstractView

  • java.lang.Object
    • org.springframework.web.reactive.result.view.AbstractView
    • Field Detail

      • REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME

        public static final java.lang.String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
        Well-known name for the RequestDataValueProcessor in the bean factory.
        See Also:
        Constant Field Values
      • logger

        protected final Log logger
        Logger that is available to subclasses.
    • Constructor Detail

      • AbstractView

        public AbstractView()
    • Method Detail

      • setSupportedMediaTypes

        public void setSupportedMediaTypes(java.util.List<MediaType> supportedMediaTypes)
        Set the supported media types for this view. Default is "text/html;charset=UTF-8".
      • getSupportedMediaTypes

        public java.util.List<MediaType> getSupportedMediaTypes()
        Return the configured media types supported by this view.
        Specified by:
        getSupportedMediaTypes in interface View
      • setDefaultCharset

        public void setDefaultCharset(java.nio.charset.Charset defaultCharset)
        Set the default charset for this view, used when the content type does not contain one. Default is UTF 8.
      • getDefaultCharset

        public java.nio.charset.Charset getDefaultCharset()
        Return the default charset, used when the content type does not contain one.
      • setRequestContextAttribute

        public void setRequestContextAttribute(@Nullable
                                               java.lang.String requestContextAttribute)
        Set the name of the RequestContext attribute for this view. Default is none.
      • getRequestContextAttribute

        @Nullable
        public java.lang.String getRequestContextAttribute()
        Return the name of the RequestContext attribute, if any.
      • setBeanName

        public void setBeanName(@Nullable
                                java.lang.String beanName)
        Set the view's name. Helpful for traceability.

        Framework code must call this when constructing views.

        Specified by:
        setBeanName in interface BeanNameAware
        Parameters:
        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.
      • getBeanName

        @Nullable
        public java.lang.String getBeanName()
        Return the view's name. Should never be null, if the view was correctly configured.
      • obtainApplicationContext

        protected final ApplicationContext obtainApplicationContext()
        Obtain the ApplicationContext for actual use.
        Returns:
        the ApplicationContext (never null)
        Throws:
        java.lang.IllegalStateException - in case of no ApplicationContext set
      • render

        public reactor.core.publisher.Mono<java.lang.Void> render(@Nullable
                                                                  java.util.Map<java.lang.String,?> model,
                                                                  @Nullable
                                                                  MediaType contentType,
                                                                  ServerWebExchange exchange)
        Prepare the model to render.
        Specified by:
        render in interface View
        Parameters:
        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 exchange
        Returns:
        Mono to represent when and if rendering succeeds
      • getModelAttributes

        protected reactor.core.publisher.Mono<java.util.Map<java.lang.String,java.lang.Object>> getModelAttributes(@Nullable
                                                                                                                   java.util.Map<java.lang.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.

      • resolveAsyncAttributes

        protected reactor.core.publisher.Mono<java.lang.Void> resolveAsyncAttributes(java.util.Map<java.lang.String,java.lang.Object> model)
        By default, resolve async attributes supported by the ReactiveAdapterRegistry to their blocking counterparts.

        View implementations capable of taking advantage of reactive types can override this method if needed.

        Returns:
        Mono for the completion of async attributes resolution
      • createRequestContext

        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.

        The default implementation creates a standard RequestContext instance for the given request and model. Can be overridden in subclasses for custom instances.

        Parameters:
        exchange - current exchange
        model - combined output Map (never null), with dynamic values taking precedence over static attributes
        Returns:
        the RequestContext instance
        See Also:
        setRequestContextAttribute(java.lang.String)
      • renderInternal

        protected abstract reactor.core.publisher.Mono<java.lang.Void> renderInternal(java.util.Map<java.lang.String,java.lang.Object> renderAttributes,
                                                                                      @Nullable
                                                                                      MediaType contentType,
                                                                                      ServerWebExchange exchange)
        Subclasses must implement this method to actually render the view.
        Parameters:
        renderAttributes - combined output Map (never null), with dynamic values taking precedence over static attributes
        contentType - 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 succeeds
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • formatViewName

        protected java.lang.String formatViewName()