Class ScriptTemplateView
java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractView
org.springframework.web.servlet.view.AbstractUrlBasedView
org.springframework.web.servlet.view.script.ScriptTemplateView
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- ServletContextAware,- View
An 
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.
 
The 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.
- Since:
- 4.2
- Author:
- Sebastien Deleuze, Juergen Hoeller
- See Also:
- 
Field SummaryFieldsFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.ViewPATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor for use as a bean.ScriptTemplateView(String url) Create a new ScriptTemplateView with the given URL.
- 
Method SummaryModifier and TypeMethodDescriptionprotected ScriptTemplateConfigbooleancheckResource(Locale locale) Check whether the underlying resource that the configured URL points to actually exists.protected ScriptEnginecreateEngineFromName(String engineName) protected ScriptEnginegetResource(String location) protected StringgetTemplate(String path) protected voidinitApplicationContext(ApplicationContext context) CallsWebApplicationObjectSupport.initServletContext(jakarta.servlet.ServletContext)if the given ApplicationContext is aWebApplicationContext.protected voidloadScripts(ScriptEngine engine) protected voidprepareResponse(HttpServletRequest request, HttpServletResponse response) Prepare the given response for rendering.protected voidrenderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) Subclasses must implement this method to actually render the view.voidsetCharset(Charset charset) SeeScriptTemplateConfigurer.setCharset(Charset)documentation.voidsetEngine(ScriptEngine engine) SeeScriptTemplateConfigurer.setEngine(ScriptEngine)documentation.voidsetEngineName(String engineName) SeeScriptTemplateConfigurer.setEngineName(String)documentation.voidsetEngineSupplier(Supplier<ScriptEngine> engineSupplier) SeeScriptTemplateConfigurer.setEngineSupplier(Supplier)documentation.voidsetRenderFunction(String functionName) SeeScriptTemplateConfigurer.setRenderFunction(String)documentation.voidsetRenderObject(String renderObject) SeeScriptTemplateConfigurer.setRenderObject(String)documentation.voidsetResourceLoaderPath(String resourceLoaderPath) SeeScriptTemplateConfigurer.setResourceLoaderPath(String)documentation.voidsetScripts(String... scripts) SeeScriptTemplateConfigurer.setScripts(String...)documentation.voidsetSharedEngine(Boolean sharedEngine) SeeScriptTemplateConfigurer.setSharedEngine(Boolean)documentation.Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedViewafterPropertiesSet, getUrl, isUrlRequired, setUrl, toStringMethods inherited from class org.springframework.web.servlet.view.AbstractViewaddStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponseMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Field Details- 
DEFAULT_CONTENT_TYPEThe default content type for the view.- See Also:
 
 
- 
- 
Constructor Details- 
ScriptTemplateViewpublic ScriptTemplateView()Constructor for use as a bean.
- 
ScriptTemplateViewCreate a new ScriptTemplateView with the given URL.- Since:
- 4.2.1
 
 
- 
- 
Method Details- 
setEngineSeeScriptTemplateConfigurer.setEngine(ScriptEngine)documentation.
- 
setEngineSupplierSeeScriptTemplateConfigurer.setEngineSupplier(Supplier)documentation.- Since:
- 5.2
 
- 
setEngineNameSeeScriptTemplateConfigurer.setEngineName(String)documentation.
- 
setScriptsSeeScriptTemplateConfigurer.setScripts(String...)documentation.
- 
setRenderObjectSeeScriptTemplateConfigurer.setRenderObject(String)documentation.
- 
setRenderFunctionSeeScriptTemplateConfigurer.setRenderFunction(String)documentation.
- 
setCharsetSeeScriptTemplateConfigurer.setCharset(Charset)documentation.
- 
setResourceLoaderPathSeeScriptTemplateConfigurer.setResourceLoaderPath(String)documentation.
- 
initApplicationContextDescription copied from class:WebApplicationObjectSupportCallsWebApplicationObjectSupport.initServletContext(jakarta.servlet.ServletContext)if the given ApplicationContext is aWebApplicationContext.- Overrides:
- initApplicationContextin class- WebApplicationObjectSupport
- Parameters:
- context- the containing ApplicationContext
- See Also:
 
- 
getEngine
- 
createEngineFromName
- 
loadScripts
- 
getResource
- 
autodetectViewConfig- Throws:
- BeansException
 
- 
checkResourceDescription copied from class:AbstractUrlBasedViewCheck whether the underlying resource that the configured URL points to actually exists.- Overrides:
- checkResourcein class- AbstractUrlBasedView
- Parameters:
- locale- the desired Locale that we're looking for
- Returns:
- trueif the resource exists (or is assumed to exist);- falseif we know that it does not exist
- Throws:
- Exception- if the resource exists but is invalid (for example, could not be parsed)
 
- 
prepareResponseDescription copied from class:AbstractViewPrepare the given response for rendering.The default implementation applies a workaround for an IE bug when sending download content via HTTPS. - Overrides:
- prepareResponsein class- AbstractView
- Parameters:
- request- current HTTP request
- response- current HTTP response
 
- 
renderMergedOutputModelprotected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws ExceptionDescription copied from class:AbstractViewSubclasses must implement this method to actually render the view.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. - Specified by:
- renderMergedOutputModelin class- AbstractView
- Parameters:
- model- combined output Map (never- null), with dynamic values taking precedence over static attributes
- request- current HTTP request
- response- current HTTP response
- Throws:
- Exception- if rendering failed
 
- 
getTemplate- Throws:
- IOException
 
 
-