org.springframework.web.reactive.result.view.freemarker

Class FreeMarkerView

    • Constructor Detail

      • FreeMarkerView

        public FreeMarkerView()
    • Method Detail

      • setConfiguration

        public void setConfiguration(@Nullable
                                     freemarker.template.Configuration configuration)
        Set the FreeMarker Configuration to be used by this view.

        Typically this property is not set directly. Instead a single FreeMarkerConfig is expected in the Spring application context which is used to obtain the FreeMarker configuration.

      • getConfiguration

        @Nullable
        protected freemarker.template.Configuration getConfiguration()
        Return the FreeMarker configuration used by this view.
      • obtainConfiguration

        protected freemarker.template.Configuration obtainConfiguration()
        Obtain the FreeMarker configuration for actual use.
        Returns:
        the FreeMarker configuration (never null)
        Throws:
        java.lang.IllegalStateException - in case of no Configuration object set
        Since:
        5.0
      • setEncoding

        public void setEncoding(@Nullable
                                java.lang.String encoding)
        Set the encoding of the FreeMarker template file.

        By default FreeMarkerConfigurer sets the default encoding in the FreeMarker configuration to "UTF-8". It's recommended to specify the encoding in the FreeMarker Configuration rather than per template if all your templates share a common encoding.

      • getEncoding

        @Nullable
        protected java.lang.String getEncoding()
        Return the encoding for the FreeMarker template.
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Description copied from interface: InitializingBean
        Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

        This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

        Specified by:
        afterPropertiesSet in interface InitializingBean
        Overrides:
        afterPropertiesSet in class AbstractUrlBasedView
        Throws:
        java.lang.Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
      • checkResourceExists

        public boolean checkResourceExists(java.util.Locale locale)
                                    throws java.lang.Exception
        Check that the FreeMarker template used for this view exists and is valid.

        Can be overridden to customize the behavior, for example in case of multiple templates to be rendered into a single view.

        Specified by:
        checkResourceExists in class AbstractUrlBasedView
        Parameters:
        locale - the desired Locale that we're looking for
        Returns:
        false if the resource exists false if we know that it does not exist
        Throws:
        java.lang.Exception - if the resource exists but is invalid (e.g. could not be parsed)
      • renderInternal

        protected reactor.core.publisher.Mono<java.lang.Void> renderInternal(java.util.Map<java.lang.String,java.lang.Object> renderAttributes,
                                                                             @Nullable
                                                                             MediaType contentType,
                                                                             ServerWebExchange exchange)
        Description copied from class: AbstractView
        Subclasses must implement this method to actually render the view.
        Specified by:
        renderInternal in class AbstractView
        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
      • getTemplateModel

        protected freemarker.template.SimpleHash getTemplateModel(java.util.Map<java.lang.String,java.lang.Object> model,
                                                                  ServerWebExchange exchange)
        Build a FreeMarker template model for the given model Map.

        The default implementation builds a SimpleHash.

        Parameters:
        model - the model to use for rendering
        exchange - current exchange
        Returns:
        the FreeMarker template model, as a SimpleHash or subclass thereof
      • getObjectWrapper

        protected freemarker.template.ObjectWrapper getObjectWrapper()
        Return the configured FreeMarker ObjectWrapper, or the default wrapper if none specified.
        See Also:
        Configurable.getObjectWrapper()
      • getTemplate

        protected freemarker.template.Template getTemplate(java.util.Locale locale)
                                                    throws java.io.IOException
        Retrieve the FreeMarker template for the given locale, to be rendering by this view.

        By default, the template specified by the "url" bean property will be retrieved.

        Parameters:
        locale - the current locale
        Returns:
        the FreeMarker template to render
        Throws:
        java.io.IOException