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
,
ScriptTemplateViewResolver
Modifier and Type | Field and Description |
---|---|
private java.nio.charset.Charset |
charset |
private javax.script.ScriptEngine |
engine |
private java.lang.String |
renderFunction |
private java.lang.String |
renderObject |
private ResourceLoader |
resourceLoader |
DEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
Constructor and Description |
---|
ScriptTemplateView() |
Modifier and Type | Method and Description |
---|---|
protected ScriptTemplateConfig |
autodetectViewConfig() |
protected java.lang.String |
getTemplate(java.lang.String path) |
protected void |
initApplicationContext(ApplicationContext context)
Calls
#initServletContext(javax.servlet.ServletContext) if the
given ApplicationContext is a WebApplicationContext . |
protected void |
renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view.
|
void |
setEngine(javax.script.ScriptEngine engine)
Set the
ScriptEngine to use in this view. |
void |
setRenderFunction(java.lang.String functionName)
Set the render function name.
|
void |
setResourceLoader(ResourceLoader resourceLoader) |
afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toString
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
private javax.script.ScriptEngine engine
private java.lang.String renderObject
private java.lang.String renderFunction
private java.nio.charset.Charset charset
private ResourceLoader resourceLoader
public void setEngine(javax.script.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.
ScriptTemplateConfig
public void setRenderFunction(java.lang.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.
ScriptTemplateConfig
public void setResourceLoader(ResourceLoader resourceLoader)
protected void initApplicationContext(ApplicationContext context)
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 ScriptTemplateConfig autodetectViewConfig() throws BeansException
BeansException
protected void renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model, HttpServletRequest request, HttpServletResponse response) throws java.lang.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 responsejava.lang.Exception
- if rendering failedprotected java.lang.String getTemplate(java.lang.String path) throws java.io.IOException
java.io.IOException