ScriptTemplateConfig for creating
a ScriptEngine for use in a web application.
// Add the following to an @Configuration class
@Bean
public ScriptTemplateConfigurer mustacheConfigurer() {
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
configurer.setEngineName("nashorn");
configurer.setScripts("mustache.js");
configurer.setRenderObject("Mustache");
configurer.setRenderFunction("render");
return configurer;
}
Note
It is possible to use non thread-safe script engines with
templating libraries not designed for concurrency, like Handlebars or React running on
Nashorn, by setting the sharedEngine property to false.
ScriptTemplateView
| Modifier and Type | Field and Description |
|---|---|
| private Charset | |
| private String | |
| private ScriptEngine | |
| private String | |
| private Supplier | |
| private String | |
| private String | |
| private String | |
| private String[] | |
| private Boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ScriptTemplateConfigurer(String engineName)
Create a new ScriptTemplateConfigurer using the given engine name. |
| Modifier and Type | Method and Description |
|---|---|
| public Charset | getCharset()
Implements org. Return the charset used to read script and template files. |
| public String | getContentType()
Implements org. Return the content type to use for the response. |
| public ScriptEngine | getEngine()
Implements org. Return the |
| public String | getEngineName()
Implements org. Return the engine name that will be used to instantiate the |
| public Supplier | getEngineSupplier()
Implements org. Return the engine supplier that will be used to instantiate the |
| public String | getRenderFunction()
Implements org. Return the render function name (optional). |
| public String | getRenderObject()
Implements org. Return the object where the render function belongs (optional). |
| public String | getResourceLoaderPath()
Implements org. Return the resource loader path(s) via a Spring resource location. |
| public String[] | getScripts()
Implements org. Return the scripts to be loaded by the script engine (library or user provided). |
| public Boolean | isSharedEngine()
Implements org. Return whether to use a shared engine for all threads or whether to create thread-local engine instances for each thread. |
| public void | |
| public void | |
| public void | |
| public void | setEngineName(String engineName)
Set the engine name that will be used to instantiate the |
| public void | setEngineSupplier(Supplier<ScriptEngine> engineSupplier)
Set the |
| public void | |
| public void | |
| public void | setResourceLoaderPath(String resourceLoaderPath)
Set the resource loader path(s) via a Spring resource location. |
| public void | setScripts(String... scriptNames)
Set the scripts to be loaded by the script engine (library or user provided). |
| public void | setSharedEngine(Boolean sharedEngine)
When set to |
| charset | back to summary |
|---|---|
| private Charset charset
| |
| contentType | back to summary |
|---|---|
| private String contentType
| |
| engine | back to summary |
|---|---|
| private ScriptEngine engine
| |
| engineName | back to summary |
|---|---|
| private String engineName
| |
| engineSupplier | back to summary |
|---|---|
| private Supplier<ScriptEngine> engineSupplier
| |
| renderFunction | back to summary |
|---|---|
| private String renderFunction
| |
| renderObject | back to summary |
|---|---|
| private String renderObject
| |
| resourceLoaderPath | back to summary |
|---|---|
| private String resourceLoaderPath
| |
| scripts | back to summary |
|---|---|
| private String[] scripts
| |
| sharedEngine | back to summary |
|---|---|
| private Boolean sharedEngine
| |
| ScriptTemplateConfigurer | back to summary |
|---|---|
| public ScriptTemplateConfigurer() Default constructor. | |
| ScriptTemplateConfigurer | back to summary |
|---|---|
| public ScriptTemplateConfigurer(String engineName) Create a new ScriptTemplateConfigurer using the given engine name. | |
| getCharset | back to summary |
|---|---|
| public Charset getCharset() Implements org. Doc from org. Return the charset used to read script and template files. | |
| getContentType | back to summary |
|---|---|
| public String getContentType() Implements org. Return the content type to use for the response. | |
| getEngine | back to summary |
|---|---|
| public ScriptEngine getEngine() Implements org. Doc from org. Return the | |
| getEngineName | back to summary |
|---|---|
| public String getEngineName() Implements org. Doc from org. Return the engine name that will be used to instantiate the | |
| getEngineSupplier | back to summary |
|---|---|
| public Supplier Implements org. Doc from org. Return the engine supplier that will be used to instantiate the | |
| getRenderFunction | back to summary |
|---|---|
| public String getRenderFunction() Implements org. Doc from org. Return the render function name (optional). If not specified, the script templates
will be evaluated with | |
| getRenderObject | back to summary |
|---|---|
| public String getRenderObject() Implements org. Doc from org. Return the object where the render function belongs (optional). | |
| getResourceLoaderPath | back to summary |
|---|---|
| public String getResourceLoaderPath() Implements org. Doc from org. Return the resource loader path(s) via a Spring resource location. | |
| getScripts | back to summary |
|---|---|
| public String[] getScripts() Implements org. Doc from org. Return the scripts to be loaded by the script engine (library or user provided). | |
| isSharedEngine | back to summary |
|---|---|
| public Boolean isSharedEngine() Implements org. Doc from org. Return whether to use a shared engine for all threads or whether to create thread-local engine instances for each thread. | |
| setCharset | back to summary |
|---|---|
| public void setCharset(Charset charset) Set the charset used to read script and template files.
( | |
| setContentType | back to summary |
|---|---|
| public void setContentType(String contentType) Set the content type to use for the response.
(
| |
| setEngine | back to summary |
|---|---|
| public void setEngine(ScriptEngine engine) Set the When the | |
| setEngineName | back to summary |
|---|---|
| public void setEngineName(String engineName) Set the engine name that will be used to instantiate the | |
| setEngineSupplier | back to summary |
|---|---|
| public void setEngineSupplier(Supplier<ScriptEngine> engineSupplier) Set the
| |
| setRenderFunction | back to summary |
|---|---|
| public void setRenderFunction(String renderFunction) Set the render function name (optional). If not specified, the script templates
will be evaluated with This function will be called with the following parameters:
| |
| setRenderObject | back to summary |
|---|---|
| public void setRenderObject(String renderObject) Set the object where the render function belongs (optional).
For example, in order to call | |
| setResourceLoaderPath | back to summary |
|---|---|
| public void setResourceLoaderPath(String resourceLoaderPath) Set the resource loader path(s) via a Spring resource location.
Accepts multiple locations as a comma-separated list of paths.
Standard URLs like "file:" and "classpath:" and pseudo URLs are supported
as understood by Spring's Default is "classpath:". | |
| setScripts | back to summary |
|---|---|
| public void setScripts(String... scriptNames) Set the scripts to be loaded by the script engine (library or user provided).
Since For example, in order to use a JavaScript library available as a WebJars dependency
and a custom "render.js" file, you should call
| |
| setSharedEngine | back to summary |
|---|---|
| public void setSharedEngine(Boolean sharedEngine) When set to When this flag is set to
| |