|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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
org.springframework.web.servlet.view.velocity.VelocityToolboxView
org.springframework.web.servlet.view.velocity.VelocityLayoutView
public class VelocityLayoutView
VelocityLayoutView emulates the functionality offered by Velocity's VelocityLayoutServlet to ease page composition from different templates.
The url
property should be set to the content template
for the view, and the layout template location should be specified as
layoutUrl
property. A view can override the configured
layout template location by setting the appropriate key (the default
is "layout") in the content template.
When the view is rendered, the VelocityContext is first merged with
the content template (specified by the url
property) and
then merged with the layout template to produce the final output.
The layout template can include the screen content through a VelocityContext variable (the default is "screen_content"). At runtime, this variable will contain the rendered content template.
setLayoutUrl(java.lang.String)
,
setLayoutKey(java.lang.String)
,
setScreenContentKey(java.lang.String)
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_LAYOUT_KEY
The default layout key . |
static java.lang.String |
DEFAULT_LAYOUT_URL
The default layout url . |
static java.lang.String |
DEFAULT_SCREEN_CONTENT_KEY
The default screen content key . |
private java.lang.String |
layoutKey
|
private java.lang.String |
layoutUrl
|
private java.lang.String |
screenContentKey
|
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 |
Fields inherited from interface org.springframework.web.servlet.View |
---|
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE |
Constructor Summary | |
---|---|
VelocityLayoutView()
|
Method Summary | |
---|---|
boolean |
checkResource(java.util.Locale locale)
Overrides VelocityView.checkTemplate() to additionally check
that both the layout template and the screen content template can be loaded. |
protected void |
doRender(Context context,
HttpServletResponse response)
Overrides the normal rendering process in order to pre-process the Context, merging it with the screen template into a single value (identified by the value of screenContentKey). |
private void |
renderScreenContent(Context velocityContext)
The resulting context contains any mappings from render, plus screen content. |
void |
setLayoutKey(java.lang.String layoutKey)
Set the context key used to specify an alternate layout to be used instead of the default layout. |
void |
setLayoutUrl(java.lang.String layoutUrl)
Set the layout template to use. |
void |
setScreenContentKey(java.lang.String screenContentKey)
Set the name of the context key that will hold the content of the screen within the layout template. |
Methods inherited from class org.springframework.web.servlet.view.velocity.VelocityToolboxView |
---|
createVelocityContext, getToolboxConfigLocation, initTool, setToolboxConfigLocation |
Methods inherited from class org.springframework.web.servlet.view.velocity.VelocityView |
---|
autodetectVelocityEngine, createVelocityContext, exposeHelpers, exposeHelpers, exposeHelpers, exposeToolAttributes, getEncoding, getTemplate, getTemplate, getVelocityEngine, initApplicationContext, isCacheTemplate, mergeTemplate, renderMergedTemplateModel, setCacheTemplate, setDateToolAttribute, setEncoding, setNumberToolAttribute, setToolAttributes, setVelocityEngine |
Methods inherited from class org.springframework.web.servlet.view.AbstractTemplateView |
---|
applyContentType, renderMergedOutputModel, setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpers |
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView |
---|
afterPropertiesSet, getUrl, isUrlRequired, setUrl, toString |
Methods inherited from class org.springframework.web.servlet.view.AbstractView |
---|
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, writeToResponse |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext |
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, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_LAYOUT_URL
layout url
.
public static final java.lang.String DEFAULT_LAYOUT_KEY
layout key
.
public static final java.lang.String DEFAULT_SCREEN_CONTENT_KEY
screen content key
.
private java.lang.String layoutUrl
private java.lang.String layoutKey
private java.lang.String screenContentKey
Constructor Detail |
---|
public VelocityLayoutView()
Method Detail |
---|
public void setLayoutUrl(java.lang.String layoutUrl)
"layout.vm"
.
layoutUrl
- the template location (relative to the template
root directory)public void setLayoutKey(java.lang.String layoutKey)
#set( $layout = "MyLayout.vm" )
Default key is "layout"
, as illustrated above.
layoutKey
- the name of the key you wish to use in your
screen content templates to override the layout templatepublic void setScreenContentKey(java.lang.String screenContentKey)
Default is "screen_content"
:
accessed in VTL as $screen_content
.
screenContentKey
- the name of the screen content key to usepublic boolean checkResource(java.util.Locale locale) throws java.lang.Exception
VelocityView.checkTemplate()
to additionally check
that both the layout template and the screen content template can be loaded.
Note that during rendering of the screen content, the layout template
can be changed which may invalidate any early checking done here.
checkResource
in class VelocityView
locale
- the desired Locale that we're looking for
true
if the resource exists (or is assumed to exist);
false
if we know that it does not exist
java.lang.Exception
- if the resource exists but is invalid (e.g. could not be parsed)protected void doRender(Context context, HttpServletResponse response) throws java.lang.Exception
doRender
in class VelocityView
context
- the Velocity context to use for renderingresponse
- servlet response (use this to get the OutputStream or Writer)
java.lang.Exception
- if thrown by VelocityAbstractUrlBasedView.setUrl(java.lang.String)
,
VelocityView.getTemplate()
,
VelocityView.mergeTemplate(Template, Context, HttpServletResponse)
private void renderScreenContent(Context velocityContext) throws java.lang.Exception
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |