public class ScriptTemplateView extends AbstractUrlBasedView
AbstractUrlBasedView
designed to run any template library based on a JSR-223 script engine.
Nashorn Javascript engine requires Java 8+.
ScriptTemplateConfigurer,
ScriptTemplateViewResolverDEFAULT_CONTENT_TYPEPATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE| Constructor and Description |
|---|
ScriptTemplateView() |
| Modifier and Type | Method and Description |
|---|---|
protected ScriptTemplateConfig |
autodetectViewConfig() |
protected String |
getTemplate(String path) |
protected void |
initApplicationContext(org.springframework.context.ApplicationContext context) |
protected void |
renderMergedOutputModel(Map<String,Object> model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view.
|
void |
setEngine(ScriptEngine engine)
Set the
ScriptEngine to use in this view. |
void |
setRenderFunction(String functionName)
Set the render function name.
|
void |
setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) |
afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toStringaddStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponsegetServletContext, getTempDir, getWebApplicationContext, initServletContext, isContextRequired, setServletContextpublic void setEngine(ScriptEngine engine)
ScriptEngine to use in this view.
If not set, the engine is auto-detected by looking up up a single
ScriptTemplateConfig bean in the web application context and using
it to obtain the configured ScriptEngine instance.
ScriptTemplateConfigpublic void setRenderFunction(String functionName)
template: the view template content (String)model: the view model (Map)If not set, the function name is auto-detected by looking up up a single
ScriptTemplateConfig bean in the web application context and using
it to obtain the configured functionName property.
ScriptTemplateConfigpublic void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
protected void initApplicationContext(org.springframework.context.ApplicationContext context)
initApplicationContext in class org.springframework.web.context.support.WebApplicationObjectSupportprotected ScriptTemplateConfig autodetectViewConfig() throws org.springframework.beans.BeansException
org.springframework.beans.BeansExceptionprotected void renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception
AbstractViewThe first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.
renderMergedOutputModel in class AbstractViewmodel - combined output Map (never null),
with dynamic values taking precedence over static attributesrequest - current HTTP requestresponse - current HTTP responseException - if rendering failedprotected String getTemplate(String path) throws IOException
IOException