Class ScriptTemplateView
- All Implemented Interfaces:
Aware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,View
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:
-
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
ConstructorDescriptionConstructor for use as a bean.ScriptTemplateView
(String url) Create a new ScriptTemplateView with the given URL. -
Method Summary
Modifier and TypeMethodDescriptionprotected ScriptTemplateConfig
boolean
checkResourceExists
(Locale locale) Check whether the resource for the configured URL actually exists.protected ScriptEngine
createEngineFromName
(String engineName) protected ScriptEngine
protected 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, MediaType contentType, ServerWebExchange exchange) Subclasses must implement this method to actually render the view.void
setApplicationContext
(ApplicationContext context) Set the ApplicationContext that this object runs in.void
setEngine
(ScriptEngine engine) SeeScriptTemplateConfigurer.setEngine(ScriptEngine)
documentation.void
setEngineName
(String engineName) SeeScriptTemplateConfigurer.setEngineName(String)
documentation.void
setEngineSupplier
(Supplier<ScriptEngine> engineSupplier) SeeScriptTemplateConfigurer.setEngineSupplier(Supplier)
documentation.void
setRenderFunction
(String functionName) SeeScriptTemplateConfigurer.setRenderFunction(String)
documentation.void
setRenderObject
(String renderObject) SeeScriptTemplateConfigurer.setRenderObject(String)
documentation.void
setResourceLoaderPath
(String resourceLoaderPath) SeeScriptTemplateConfigurer.setResourceLoaderPath(String)
documentation.void
setScripts
(String... scripts) SeeScriptTemplateConfigurer.setScripts(String...)
documentation.void
setSharedEngine
(Boolean sharedEngine) SeeScriptTemplateConfigurer.setSharedEngine(Boolean)
documentation.Methods inherited from class org.springframework.web.reactive.result.view.AbstractUrlBasedView
afterPropertiesSet, getUrl, resourceExists, 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, 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 Details
-
ScriptTemplateView
public ScriptTemplateView()Constructor for use as a bean. -
ScriptTemplateView
Create a new ScriptTemplateView with the given URL.
-
-
Method Details
-
setEngine
SeeScriptTemplateConfigurer.setEngine(ScriptEngine)
documentation. -
setEngineSupplier
SeeScriptTemplateConfigurer.setEngineSupplier(Supplier)
documentation.- Since:
- 5.2
-
setEngineName
SeeScriptTemplateConfigurer.setEngineName(String)
documentation. -
setScripts
SeeScriptTemplateConfigurer.setScripts(String...)
documentation. -
setRenderObject
SeeScriptTemplateConfigurer.setRenderObject(String)
documentation. -
setRenderFunction
SeeScriptTemplateConfigurer.setRenderFunction(String)
documentation. -
setResourceLoaderPath
SeeScriptTemplateConfigurer.setResourceLoaderPath(String)
documentation. -
setApplicationContext
Description copied from interface:ApplicationContextAware
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
InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
andMessageSourceAware
, if applicable.- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Overrides:
setApplicationContext
in classAbstractView
- Parameters:
context
- the ApplicationContext object to be used by this object- See Also:
-
getEngine
-
createEngineFromName
-
loadScripts
-
getResource
-
autodetectViewConfig
- Throws:
BeansException
-
checkResourceExists
Description copied from class:AbstractUrlBasedView
Check whether the resource for the configured URL actually exists.- Specified by:
checkResourceExists
in classAbstractUrlBasedView
- Parameters:
locale
- the desired Locale that we're looking for- Returns:
false
if the resource existsfalse
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 MediaType contentType, ServerWebExchange exchange) Description copied from class:AbstractView
Subclasses must implement this method to actually render the view.- Specified by:
renderInternal
in classAbstractView
- Parameters:
model
- combined output Map (nevernull
), with dynamic values taking precedence over static attributescontentType
- the content type selected to render with, which should match one of the supported media typesexchange
- current exchange- Returns:
- a
Mono
that represents when and if rendering succeeds
-
getTemplate
- Throws:
IOException
-