Class ScriptTemplateConfigurer
- All Implemented Interfaces:
- ScriptTemplateConfig
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.
- Since:
- 5.0
- Author:
- Sebastien Deleuze
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionDefault constructor.ScriptTemplateConfigurer(String engineName) Create a new ScriptTemplateConfigurer using the given engine name.
- 
Method SummaryModifier and TypeMethodDescriptionReturn the charset used to read script and template files.Return theScriptEngineto use by the views.Return the engine name that will be used to instantiate theScriptEngine.Return the engine supplier that will be used to instantiate theScriptEngine.Return the render function name (optional).Return the object where the render function belongs (optional).Return the resource loader path(s) via a Spring resource location.String[]Return the scripts to be loaded by the script engine (library or user provided).Return whether to use a shared engine for all threads or whether to create thread-local engine instances for each thread.voidsetCharset(Charset charset) Set the charset used to read script and template files.voidsetEngine(ScriptEngine engine) Set theScriptEngineto use by the view.voidsetEngineName(String engineName) Set the engine name that will be used to instantiate theScriptEngine.voidsetEngineSupplier(Supplier<ScriptEngine> engineSupplier) Set theScriptEnginesupplier to use by the view, usually used withsetSharedEngine(Boolean)set tofalse.voidsetRenderFunction(String renderFunction) Set the render function name (optional).voidsetRenderObject(String renderObject) Set the object where the render function belongs (optional).voidsetResourceLoaderPath(String resourceLoaderPath) Set the resource loader path(s) via a Spring resource location.voidsetScripts(String... scriptNames) Set the scripts to be loaded by the script engine (library or user provided).voidsetSharedEngine(Boolean sharedEngine) When set tofalse, a newScriptEngineinstance will be created for each request, else the same instance will be reused.
- 
Constructor Details- 
ScriptTemplateConfigurerpublic ScriptTemplateConfigurer()Default constructor.
- 
ScriptTemplateConfigurerCreate a new ScriptTemplateConfigurer using the given engine name.
 
- 
- 
Method Details- 
setEngineSet theScriptEngineto use by the view. IfrenderFunctionis specified, the script engine must implementInvocable. You must defineengineorengineName, not both.When the sharedEngineflag is set tofalse, you should not specify the script engine with this setter, but with thesetEngineName(String)orsetEngineSupplier(Supplier)(since it implies multiple lazy instantiations of the script engine).
- 
getEngineDescription copied from interface:ScriptTemplateConfigReturn theScriptEngineto use by the views.- Specified by:
- getEnginein interface- ScriptTemplateConfig
 
- 
setEngineSupplierSet theScriptEnginesupplier to use by the view, usually used withsetSharedEngine(Boolean)set tofalse. IfrenderFunctionis specified, the script engine must implementInvocable. You must either defineengineSupplier,engineorengineName.- Since:
- 5.2
- See Also:
 
- 
getEngineSupplierDescription copied from interface:ScriptTemplateConfigReturn the engine supplier that will be used to instantiate theScriptEngine.- Specified by:
- getEngineSupplierin interface- ScriptTemplateConfig
 
- 
setEngineNameSet the engine name that will be used to instantiate theScriptEngine. IfrenderFunctionis specified, the script engine must implementInvocable. You must defineengineorengineName, not both.
- 
getEngineNameDescription copied from interface:ScriptTemplateConfigReturn the engine name that will be used to instantiate theScriptEngine.- Specified by:
- getEngineNamein interface- ScriptTemplateConfig
 
- 
setScriptsSet the scripts to be loaded by the script engine (library or user provided). SinceresourceLoaderPathdefault value is "classpath:", you can load easily any script available on the classpath.For example, in order to use a JavaScript library available as a WebJars dependency and a custom "render.js" file, you should call configurer.setScripts("/META-INF/resources/webjars/library/version/library.js", "com/myproject/script/render.js");.
- 
getScriptsDescription copied from interface:ScriptTemplateConfigReturn the scripts to be loaded by the script engine (library or user provided).- Specified by:
- getScriptsin interface- ScriptTemplateConfig
 
- 
setRenderObjectSet the object where the render function belongs (optional). For example, in order to callMustache.render(),renderObjectshould be set to"Mustache"andrenderFunctionto"render".
- 
getRenderObjectDescription copied from interface:ScriptTemplateConfigReturn the object where the render function belongs (optional).- Specified by:
- getRenderObjectin interface- ScriptTemplateConfig
 
- 
setRenderFunctionSet the render function name (optional). If not specified, the script templates will be evaluated withScriptEngine.eval(String, Bindings).This function will be called with the following parameters: - String template: the template content
- Map model: the view model
- RenderingContext context: the rendering context
 - See Also:
 
- 
getRenderFunctionDescription copied from interface:ScriptTemplateConfigReturn the render function name (optional). If not specified, the script templates will be evaluated withScriptEngine.eval(String, Bindings).- Specified by:
- getRenderFunctionin interface- ScriptTemplateConfig
 
- 
setCharsetSet the charset used to read script and template files. (UTF-8by default).
- 
getCharsetDescription copied from interface:ScriptTemplateConfigReturn the charset used to read script and template files.- Specified by:
- getCharsetin interface- ScriptTemplateConfig
 
- 
setResourceLoaderPathSet 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'sResourceLoader. Relative paths are allowed when running in an ApplicationContext.Default is "classpath:". 
- 
getResourceLoaderPathDescription copied from interface:ScriptTemplateConfigReturn the resource loader path(s) via a Spring resource location.- Specified by:
- getResourceLoaderPathin interface- ScriptTemplateConfig
 
 
-