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.
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
,
ScriptTemplateViewResolver
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CONTENT_TYPE |
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
Constructor and Description |
---|
ScriptTemplateView()
Constructor for use as a bean.
|
ScriptTemplateView(String url)
Create a new ScriptTemplateView with the given URL.
|
afterPropertiesSet, getUrl, isUrlRequired, setUrl, toString
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
public static final String DEFAULT_CONTENT_TYPE
public ScriptTemplateView()
public ScriptTemplateView(String url)
public void setEngine(ScriptEngine engine)
ScriptTemplateConfigurer.setEngine(ScriptEngine)
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 setContentType(String contentType)
ScriptTemplateConfigurer.setContentType(String)
} documentation.setContentType
in class AbstractView
public void setCharset(Charset charset)
ScriptTemplateConfigurer.setCharset(Charset)
documentation.public void setResourceLoaderPath(String resourceLoaderPath)
ScriptTemplateConfigurer.setResourceLoaderPath(String)
documentation.protected void initApplicationContext(ApplicationContext context)
WebApplicationObjectSupport
WebApplicationObjectSupport.initServletContext(javax.servlet.ServletContext)
if the
given ApplicationContext is a WebApplicationContext
.initApplicationContext
in class WebApplicationObjectSupport
context
- the containing ApplicationContextApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
protected ScriptEngine getEngine()
protected ScriptEngine createEngineFromName()
protected void loadScripts(ScriptEngine engine)
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException
BeansException
public boolean checkResource(Locale locale) throws Exception
AbstractUrlBasedView
checkResource
in class AbstractUrlBasedView
locale
- the desired Locale that we're looking fortrue
if the resource exists (or is assumed to exist);
false
if we know that it does not existException
- if the resource exists but is invalid (e.g. could not be parsed)protected void prepareResponse(HttpServletRequest request, HttpServletResponse response)
AbstractView
The default implementation applies a workaround for an IE bug when sending download content via HTTPS.
prepareResponse
in class AbstractView
request
- current HTTP requestresponse
- current HTTP responseprotected void renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception
AbstractView
The 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 AbstractView
model
- 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