org.springframework.web.servlet.view.velocity

## Class VelocityViewResolver

- java.lang.Object
- - org.springframework.context.support.ApplicationObjectSupport
  - - org.springframework.web.context.support.WebApplicationObjectSupport
    - - org.springframework.web.servlet.view.AbstractCachingViewResolver
      - - org.springframework.web.servlet.view.UrlBasedViewResolver
        - - org.springframework.web.servlet.view.AbstractTemplateViewResolver
          - - org.springframework.web.servlet.view.velocity.VelocityViewResolver

All Implemented Interfaces:
  Aware, ApplicationContextAware, Ordered, ServletContextAware, ViewResolver

Direct Known Subclasses:
  VelocityLayoutViewResolver

    public class VelocityViewResolver
    extends AbstractTemplateViewResolver

Convenience subclass of `UrlBasedViewResolver` that supports `VelocityView` (i.e. Velocity templates) and custom subclasses of it.

The view class for all views generated by this resolver can be specified via the "viewClass" property. See UrlBasedViewResolver's javadoc for details.

Note: When chaining ViewResolvers, a VelocityViewResolver will check for the existence of the specified template resources and only return a non-null View object if the template was actually found.

Since:
  13.12.2003
Author:
  Juergen Hoeller
See Also:
  `UrlBasedViewResolver.setViewClass(java.lang.Class)`, `UrlBasedViewResolver.setPrefix(java.lang.String)`, `UrlBasedViewResolver.setSuffix(java.lang.String)`, `UrlBasedViewResolver.setRequestContextAttribute(java.lang.String)`, `AbstractTemplateViewResolver.setExposeSpringMacroHelpers(boolean)`, `setDateToolAttribute(java.lang.String)`, `setNumberToolAttribute(java.lang.String)`, `VelocityView`

### Field Summary

### Fields inherited from class org.springframework.web.servlet.view.UrlBasedViewResolver

`FORWARD_URL_PREFIX, REDIRECT_URL_PREFIX`

### Fields inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver

`DEFAULT_CACHE_LIMIT`

### Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

`logger`

### Fields inherited from interface org.springframework.core.Ordered

`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

### Constructor Summary

Constructors
Constructor and Description
`VelocityViewResolver()`

### Method Summary

Methods
`protected AbstractUrlBasedView` `buildView(String viewName)` Creates a new View instance of the specified view class and configures it.
`protected void` `initApplicationContext()` Subclasses can override this for custom initialization behavior.
`protected Class` `requiredViewClass()` Requires `VelocityView`.
`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` `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` `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.AbstractTemplateViewResolver

`setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpers`

### Methods inherited from class org.springframework.web.servlet.view.UrlBasedViewResolver

`canHandle, createView, getAttributesMap, getCacheKey, getContentType, getOrder, getPrefix, getRequestContextAttribute, getSuffix, getViewClass, getViewNames, isRedirectContextRelative, isRedirectHttp10Compatible, loadView, setAttributes, setAttributesMap, setContentType, setExposePathVariables, setOrder, setPrefix, setRedirectContextRelative, setRedirectHttp10Compatible, setRequestContextAttribute, setSuffix, setViewClass, setViewNames`

### Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver

`clearCache, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheLimit, setCacheUnresolved`

### 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, toString, wait, wait, wait`

### Constructor Detail

#### VelocityViewResolver

    public VelocityViewResolver()

### Method Detail

#### requiredViewClass

    protected Class requiredViewClass()

Requires `VelocityView`.

Overrides:
  `requiredViewClass` in class `AbstractTemplateViewResolver`
See Also:
  `AbstractUrlBasedView`

#### setDateToolAttribute

    public 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. DateTool is part of Velocity Tools 1.0.

See Also:
  `DateTool`, `VelocityView.setDateToolAttribute(java.lang.String)`

#### setNumberToolAttribute

    public 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. NumberTool is part of Velocity Tools 1.1.

See Also:
  `NumberTool`, `VelocityView.setNumberToolAttribute(java.lang.String)`

#### 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.

Note: Specifying a toolbox config location will lead to VelocityToolboxView instances being created.

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

#### initApplicationContext

    protected void initApplicationContext()

Description copied from class: `ApplicationObjectSupport`
Subclasses can override this for custom initialization behavior.

The default implementation is empty. Called by `ApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext)`.

Overrides:
  `initApplicationContext` in class `UrlBasedViewResolver`
See Also:
  `ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)`

#### buildView

    protected AbstractUrlBasedView buildView(String viewName)
                                      throws Exception

Description copied from class: `UrlBasedViewResolver`
Creates a new View instance of the specified view class and configures it. Does not perform any lookup for pre-defined View instances.

Spring lifecycle methods as defined by the bean container do not have to be called here; those will be applied by the `loadView` method after this method returns.

Subclasses will typically call `super.buildView(viewName)` first, before setting further properties themselves. `loadView` will then apply Spring lifecycle methods at the end of this process.

Overrides:
  `buildView` in class `AbstractTemplateViewResolver`
Parameters:
  `viewName` - the name of the view to build
Returns:
  the View instance
Throws:
  `Exception` - if the view couldn't be resolved
See Also:
  `UrlBasedViewResolver.loadView(String, java.util.Locale)`