站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 1.2.9 API 文档英文版

VelocityToolboxView (Spring Framework) - Spring Framework 1.2.9 API 文档英文版


org.springframework.web.servlet.view.velocity
Class VelocityToolboxView

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.view.AbstractView
              extended by org.springframework.web.servlet.view.AbstractUrlBasedView
                  extended by org.springframework.web.servlet.view.AbstractTemplateView
                      extended by org.springframework.web.servlet.view.velocity.VelocityView
                          extended by org.springframework.web.servlet.view.velocity.VelocityToolboxView
All Implemented Interfaces:
BeanNameAware, InitializingBean, ApplicationContextAware, View
Direct Known Subclasses:
VelocityLayoutView

public class VelocityToolboxView
extends VelocityView

VelocityView subclass which adds support for Velocity Tools toolboxes and Velocity Tools' ViewTool callbacks.

Specify a "toolboxConfigLocation", for example "/WEB-INF/toolbox.xml", to automatically load a Velocity Tools toolbox definition file and expose all defined tools in the specified scopes. If no config location is specified, no toolbox will be loaded and exposed.

This view will always create a special Velocity context, namely an instance of the ChainedContext class which is part of the view package of Velocity tools. This allows to use tools from the view package of Velocity Tools, like LinkTool, which need to be initialized with a special context that implements the ViewContext interface (that is, ChainedContext).

This view also checks tools that are specified as "toolAttributes": If they implement the ViewTool interface, they will get initialized with the Velocity context. This allows tools from the view package of Velocity Tools, like LinkTool, to be defined as "toolAttributes" on a VelocityView, instead of in a separate toolbox XML file.

This is a separate class mainly to avoid a required dependency on the view package of Velocity Tools in VelocityView itself.

Since:
1.1.3
Author:
Juergen Hoeller
See Also:
setToolboxConfigLocation(java.lang.String), initTool(java.lang.Object, org.apache.velocity.context.Context), ChainedContext, ViewTool, LinkTool

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
VelocityToolboxView()
           
 
Method Summary
protected  org.apache.velocity.context.Context createVelocityContext(Map model, HttpServletRequest request, HttpServletResponse response)
          Overridden to create a ChainedContext, which is part of the view package of Velocity Tools, as special context.
protected  String getToolboxConfigLocation()
          Return the Velocity Toolbox config location, if any.
protected  void initTool(Object tool, org.apache.velocity.context.Context velocityContext)
          Overridden to check for the ViewContext interface which is part of the view package of Velocity Tools.
 void setToolboxConfigLocation(String toolboxConfigLocation)
          Set a Velocity Toolbox config location, for example "/WEB-INF/toolbox.xml", to automatically load a Velocity Tools toolbox definition file and expose all defined tools in the specified scopes.
 
Methods inherited from class org.springframework.web.servlet.view.velocity.VelocityView
autodetectVelocityEngine, checkTemplate, createVelocityContext, doRender, exposeHelpers, exposeHelpers, exposeHelpers, exposeToolAttributes, getEncoding, getTemplate, getTemplate, getVelocityEngine, initApplicationContext, isCacheTemplate, mergeTemplate, renderMergedTemplateModel, setCacheTemplate, setDateToolAttribute, setEncoding, setNumberToolAttribute, setToolAttributes, setVelocityEngine, setVelocityFormatterAttribute
 
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
afterPropertiesSet, getUrl, setUrl, toString
 
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, isContextRequired
 
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
 

Constructor Detail

VelocityToolboxView

public VelocityToolboxView()
Method Detail

setToolboxConfigLocation

public void setToolboxConfigLocation(String toolboxConfigLocation)
Set a Velocity Toolbox config location, for example "/WEB-INF/toolbox.xml", to automatically load a Velocity Tools toolbox definition file and expose all defined tools in the specified scopes. If no config location is specified, no toolbox will be loaded and exposed.

The specfied location string needs to refer to a ServletContext resource, as expected by ServletToolboxManager which is part of the view package of Velocity Tools.

See Also:
ServletToolboxManager.getInstance(javax.servlet.ServletContext, java.lang.String)

getToolboxConfigLocation

protected String getToolboxConfigLocation()
Return the Velocity Toolbox config location, if any.


createVelocityContext

protected org.apache.velocity.context.Context createVelocityContext(Map model,
                                                                    HttpServletRequest request,
                                                                    HttpServletResponse response)
                                                             throws Exception
Overridden to create a ChainedContext, which is part of the view package of Velocity Tools, as special context. ChainedContext is needed for initialization of ViewTool instances.

Overrides:
createVelocityContext in class VelocityView
Parameters:
model - the model Map, containing the model attributes to be exposed to the view
request - current HTTP request
response - current HTTP response
Returns:
the Velocity Context
Throws:
Exception - if there's a fatal error while creating the context
See Also:
initTool(java.lang.Object, org.apache.velocity.context.Context)

initTool

protected void initTool(Object tool,
                        org.apache.velocity.context.Context velocityContext)
                 throws Exception
Overridden to check for the ViewContext interface which is part of the view package of Velocity Tools. This requires a special Velocity context, like ChainedContext as set up by createVelocityContext in this class.

Overrides:
initTool in class VelocityView
Parameters:
tool - the tool instance to initialize
velocityContext - the Velocity context
Throws:
Exception - if initializion of the tool failed
See Also:
createVelocityContext(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


Copyright (c) 2002-2007 The Spring Framework Project.