public class ScriptTemplateView extends AbstractUrlBasedView
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.
ScriptTemplateConfigurer,
ScriptTemplateViewResolverlogger, REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAMEBINDING_CONTEXT_ATTRIBUTE| Constructor and Description |
|---|
ScriptTemplateView()
Constructor for use as a bean.
|
ScriptTemplateView(String url)
Create a new ScriptTemplateView with the given URL.
|
| Modifier and Type | Method and Description |
|---|---|
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. |
afterPropertiesSet, getUrl, setUrl, toStringcreateRequestContext, formatViewName, getApplicationContext, getBeanName, getDefaultCharset, getModelAttributes, getRequestContextAttribute, getRequestDataValueProcessor, getSupportedMediaTypes, obtainApplicationContext, render, resolveAsyncAttributes, resolveAsyncAttributes, setBeanName, setDefaultCharset, setRequestContextAttribute, setSupportedMediaTypesclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisRedirectViewpublic ScriptTemplateView()
public ScriptTemplateView(String url)
public void setEngine(ScriptEngine engine)
ScriptTemplateConfigurer.setEngine(ScriptEngine) documentation.public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier)
ScriptTemplateConfigurer.setEngineSupplier(Supplier) documentation.public void setEngineName(String engineName)
ScriptTemplateConfigurer.setEngineName(String) documentation.public void setSharedEngine(Boolean sharedEngine)
ScriptTemplateConfigurer.setSharedEngine(Boolean) documentation.public void setScripts(String... scripts)
ScriptTemplateConfigurer.setScripts(String...) documentation.public void setRenderObject(String renderObject)
ScriptTemplateConfigurer.setRenderObject(String) documentation.public void setRenderFunction(String functionName)
ScriptTemplateConfigurer.setRenderFunction(String) documentation.public void setResourceLoaderPath(String resourceLoaderPath)
ScriptTemplateConfigurer.setResourceLoaderPath(String) documentation.public void setApplicationContext(@Nullable
org.springframework.context.ApplicationContext context)
setApplicationContext in interface org.springframework.context.ApplicationContextAwaresetApplicationContext in class AbstractViewprotected ScriptEngine getEngine()
protected ScriptEngine createEngineFromName(String engineName)
protected void loadScripts(ScriptEngine engine)
@Nullable protected org.springframework.core.io.Resource getResource(String location)
protected ScriptTemplateConfig autodetectViewConfig() throws org.springframework.beans.BeansException
org.springframework.beans.BeansExceptionpublic boolean checkResourceExists(Locale locale) throws Exception
AbstractUrlBasedViewcheckResourceExists in class AbstractUrlBasedViewlocale - the desired Locale that we're looking forfalse if the resource exists
false if we know that it does not existException - if the resource exists but is invalid (e.g. could not be parsed)protected reactor.core.publisher.Mono<Void> renderInternal(Map<String,Object> model, @Nullable org.springframework.http.MediaType contentType, org.springframework.web.server.ServerWebExchange exchange)
AbstractViewrenderInternal in class AbstractViewmodel - combined output Map (never null),
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 exchangeMono that represents when and if rendering succeedsprotected String getTemplate(String path) throws IOException
IOException