org.springframework.web.reactive.result.view.script

## Class ScriptTemplateView

- java.lang.Object
- - org.springframework.web.reactive.result.view.AbstractView
  - - org.springframework.web.reactive.result.view.AbstractUrlBasedView
    - - org.springframework.web.reactive.result.view.script.ScriptTemplateView

All Implemented Interfaces:
  org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, View

    public class ScriptTemplateView
    extends AbstractUrlBasedView

An `AbstractUrlBasedView` subclass designed to run any template library based on a JSR-223 script engine.

If not set, each property is auto-detected by looking up a single `ScriptTemplateConfig` bean in the web application context and using it to obtain the configured properties.

The Nashorn JavaScript engine requires Java 8+ and may require setting the `sharedEngine` property to `false` in order to run properly. See `ScriptTemplateConfigurer.setSharedEngine(Boolean)` for more details.

Since:
  5.0
Author:
  Sebastien Deleuze, Juergen Hoeller
See Also:
  `ScriptTemplateConfigurer`, `ScriptTemplateViewResolver`

### Field Summary

### Fields inherited from class org.springframework.web.reactive.result.view.AbstractView

`logger, REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME`

### Fields inherited from interface org.springframework.web.reactive.result.view.View

`BINDING_CONTEXT_ATTRIBUTE`

### Constructor Summary

Constructors
Constructor and Description
`ScriptTemplateView()` Constructor for use as a bean.
`ScriptTemplateView(String url)` Create a new ScriptTemplateView with the given URL.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected ScriptTemplateConfig` `autodetectViewConfig()`
`boolean` `checkResourceExists(Locale locale)` Check whether the resource for the configured URL actually exists.
`protected ScriptEngine` `createEngineFromName(String engineName)`
`protected ScriptEngine` `getEngine()`
`protected org.springframework.core.io.Resource` `getResource(String location)`
`protected String` `getTemplate(String path)`
`protected void` `loadScripts(ScriptEngine engine)`
`protected reactor.core.publisher.Mono<Void>` `renderInternal(Map<String,Object> model, org.springframework.http.MediaType contentType, org.springframework.web.server.ServerWebExchange exchange)` Subclasses must implement this method to actually render the view.
`void` `setApplicationContext(org.springframework.context.ApplicationContext context)`
`void` `setEngine(ScriptEngine engine)` See `ScriptTemplateConfigurer.setEngine(ScriptEngine)` documentation.
`void` `setEngineName(String engineName)` See `ScriptTemplateConfigurer.setEngineName(String)` documentation.
`void` `setEngineSupplier(Supplier<ScriptEngine> engineSupplier)` See `ScriptTemplateConfigurer.setEngineSupplier(Supplier)` documentation.
`void` `setRenderFunction(String functionName)` See `ScriptTemplateConfigurer.setRenderFunction(String)` documentation.
`void` `setRenderObject(String renderObject)` See `ScriptTemplateConfigurer.setRenderObject(String)` documentation.
`void` `setResourceLoaderPath(String resourceLoaderPath)` See `ScriptTemplateConfigurer.setResourceLoaderPath(String)` documentation.
`void` `setScripts(String... scripts)` See `ScriptTemplateConfigurer.setScripts(String...)` documentation.
`void` `setSharedEngine(Boolean sharedEngine)` See `ScriptTemplateConfigurer.setSharedEngine(Boolean)` documentation.

### Methods inherited from class org.springframework.web.reactive.result.view.AbstractUrlBasedView

`afterPropertiesSet, getUrl, setUrl, toString`

### Methods inherited from class org.springframework.web.reactive.result.view.AbstractView

`createRequestContext, formatViewName, getApplicationContext, getBeanName, getDefaultCharset, getModelAttributes, getRequestContextAttribute, getRequestDataValueProcessor, getSupportedMediaTypes, obtainApplicationContext, render, resolveAsyncAttributes, resolveAsyncAttributes, setBeanName, setDefaultCharset, setRequestContextAttribute, setSupportedMediaTypes`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.web.reactive.result.view.View

`isRedirectView`

### Constructor Detail

#### ScriptTemplateView

    public ScriptTemplateView()

Constructor for use as a bean.

See Also:
  `AbstractUrlBasedView.setUrl(java.lang.String)`

#### ScriptTemplateView

    public ScriptTemplateView(String url)

Create a new ScriptTemplateView with the given URL.

### Method Detail

#### setEngine

    public void setEngine(ScriptEngine engine)

See `ScriptTemplateConfigurer.setEngine(ScriptEngine)` documentation.

#### setEngineSupplier

    public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier)

See `ScriptTemplateConfigurer.setEngineSupplier(Supplier)` documentation.

Since:
  5.2

#### setEngineName

    public void setEngineName(String engineName)

See `ScriptTemplateConfigurer.setEngineName(String)` documentation.

#### setSharedEngine

    public void setSharedEngine(Boolean sharedEngine)

See `ScriptTemplateConfigurer.setSharedEngine(Boolean)` documentation.

#### setScripts

    public void setScripts(String... scripts)

See `ScriptTemplateConfigurer.setScripts(String...)` documentation.

#### setRenderObject

    public void setRenderObject(String renderObject)

See `ScriptTemplateConfigurer.setRenderObject(String)` documentation.

#### setRenderFunction

    public void setRenderFunction(String functionName)

See `ScriptTemplateConfigurer.setRenderFunction(String)` documentation.

#### setResourceLoaderPath

    public void setResourceLoaderPath(String resourceLoaderPath)

See `ScriptTemplateConfigurer.setResourceLoaderPath(String)` documentation.

#### setApplicationContext

    public void setApplicationContext(@Nullable
                                      org.springframework.context.ApplicationContext context)

Specified by:
  `setApplicationContext` in interface `org.springframework.context.ApplicationContextAware`
Overrides:
  `setApplicationContext` in class `AbstractView`

#### getEngine

    protected ScriptEngine getEngine()

#### createEngineFromName

    protected ScriptEngine createEngineFromName(String engineName)

#### loadScripts

    protected void loadScripts(ScriptEngine engine)

#### getResource

    @Nullable
    protected org.springframework.core.io.Resource getResource(String location)

#### autodetectViewConfig

    protected ScriptTemplateConfig autodetectViewConfig()
                                                 throws org.springframework.beans.BeansException

Throws:
  `org.springframework.beans.BeansException`

#### checkResourceExists

    public boolean checkResourceExists(Locale locale)
                                throws Exception

Description copied from class: `AbstractUrlBasedView`
Check whether the resource for the configured URL actually exists.

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:
  `Exception` - if the resource exists but is invalid (e.g. could not be parsed)

#### renderInternal

    protected reactor.core.publisher.Mono<Void> renderInternal(Map<String,Object> model,
                                                               @Nullable
                                                               org.springframework.http.MediaType contentType,
                                                               org.springframework.web.server.ServerWebExchange exchange)

Description copied from class: `AbstractView`
Subclasses must implement this method to actually render the view.

Specified by:
  `renderInternal` in class `AbstractView`
Parameters:
  `model` - 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
Returns:
  a `Mono` that represents when and if rendering succeeds

#### getTemplate

    protected String getTemplate(String path)
                          throws IOException

Throws:
  `IOException`