|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.AbstractTemplateView org.springframework.web.servlet.view.velocity.VelocityView
View using the Velocity template engine. Based on code in the VelocityServlet shipped with Velocity.
Exposes the following JavaBean properties:
Depends on a VelocityConfig object such as VelocityConfigurer being accessible in the current web application context, with any bean name. Alternatively, you can set the VelocityEngine object as bean property.
VelocityConfig
,
VelocityConfigurer
,
AbstractUrlBasedView.setUrl(java.lang.String)
,
AbstractTemplateView.setExposeSpringMacroHelpers(boolean)
,
setEncoding(java.lang.String)
,
setVelocityEngine(org.apache.velocity.app.VelocityEngine)
,
VelocityConfig
,
VelocityConfigurer
Field Summary |
Fields inherited from class org.springframework.web.servlet.view.AbstractTemplateView |
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE |
Fields inherited from class org.springframework.web.servlet.view.AbstractView |
DEFAULT_CONTENT_TYPE |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
logger |
Constructor Summary | |
VelocityView()
|
Method Summary | |
protected Context |
createVelocityContext(Map model)
Create a Velocity Context instance for the given model. |
protected void |
exposeHelpers(Context velocityContext,
HttpServletRequest request)
Deprecated. in favor of exposeHelpers(Map, HttpServletRequest) |
protected void |
exposeHelpers(Map model,
HttpServletRequest request)
Expose helpers unique to each rendering operation. |
protected String |
getEncoding()
Return the encoding for the Velocity template. |
protected Template |
getTemplate()
Retrieve the Velocity template. |
protected VelocityEngine |
getVelocityEngine()
Return the VelocityEngine used by this view. |
protected void |
initApplicationContext()
Invoked on startup. |
protected void |
mergeTemplate(Template template,
Context context,
HttpServletResponse response)
Merge the template with the context. |
protected void |
renderMergedTemplateModel(Map model,
HttpServletRequest request,
HttpServletResponse response)
Process the model map by merging it with the Velocity template. |
void |
setCacheTemplate(boolean cacheTemplate)
Set whether the Velocity template should be cached. |
void |
setDateToolAttribute(String dateToolAttribute)
Set the name of the DateTool helper object to expose in the Velocity context of this view, or null if not needed. |
void |
setEncoding(String encoding)
Set the encoding of the Velocity template file. |
void |
setNumberToolAttribute(String numberToolAttribute)
Set the name of the NumberTool helper object to expose in the Velocity context of this view, or null if not needed. |
void |
setVelocityEngine(VelocityEngine velocityEngine)
Set the VelocityEngine to be used by this view. |
void |
setVelocityFormatterAttribute(String velocityFormatterAttribute)
Set the name of the VelocityFormatter helper object to expose in the Velocity context of this view, or null if not needed. |
Methods inherited from class org.springframework.web.servlet.view.AbstractTemplateView |
renderMergedOutputModel, setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpers |
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView |
getUrl, setUrl |
Methods inherited from class org.springframework.web.servlet.view.AbstractView |
addStaticAttribute, createRequestContext, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
getServletContext, getTempDir, getWebApplicationContext |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public VelocityView()
Method Detail |
public void setEncoding(String encoding)
Specify the encoding in the VelocityEngine rather than per template if all your templates share a common encoding.
protected String getEncoding()
public void setVelocityFormatterAttribute(String velocityFormatterAttribute)
VelocityFormatter
public void setDateToolAttribute(String dateToolAttribute)
DateTool
public void setNumberToolAttribute(String numberToolAttribute)
NumberTool
public void setCacheTemplate(boolean cacheTemplate)
Note that this is a minor optimization only, as Velocity itself caches templates in a modification-aware fashion.
public void setVelocityEngine(VelocityEngine velocityEngine)
VelocityConfig
protected VelocityEngine getVelocityEngine()
protected void initApplicationContext() throws BeansException
initApplicationContext
in class AbstractUrlBasedView
BeansException
protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
renderMergedTemplateModel
in class AbstractTemplateView
model
- combined output Map, with request attributes and
session attributes merged into it if requiredrequest
- current HTTP requestresponse
- current HTTP response
Exception
- if rendering failedprotected Template getTemplate() throws Exception
Exception
- if thrown by Velocityprotected void exposeHelpers(Map model, HttpServletRequest request) throws Exception
Called by renderMergedTemplateModel. The default implementation is empty. This method can be overridden to add custom helpers to the model.
model
- the model that will be passed to the template at merge timerequest
- current HTTP request
Exception
- if there's a fatal error while we're adding model attributesrenderMergedTemplateModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected Context createVelocityContext(Map model)
Default implementation creates an instance of Velocity's VelocityContext implementation class.
model
- the model Map, containing the model attributes
to be exposed to the view
VelocityContext
protected void exposeHelpers(Context velocityContext, HttpServletRequest request) throws Exception
Called by renderMergedTemplateModel. The default implementations is empty. This method can be overridden to add custom helpers to the Velocity context.
velocityContext
- Velocity context that will be passed to the template at merge timerequest
- current HTTP request
Exception
- if there's a fatal error while we're adding model attributesexposeHelpers(Map, HttpServletRequest)
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception
template
- the template to mergecontext
- the Velocity contextresponse
- servlet response (use this to get the OutputStream or Writer)
Exception
Template.merge(org.apache.velocity.context.Context, java.io.Writer)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |