com.interface21.web.servlet.view.velocity
Class VelocityView

java.lang.Object
  |
  +--com.interface21.context.support.ApplicationObjectSupport
        |
        +--com.interface21.web.servlet.view.AbstractView
              |
              +--com.interface21.web.servlet.view.velocity.VelocityView
All Implemented Interfaces:
ApplicationContextAware, View

public class VelocityView
extends AbstractView

View using Velocity template engine. Based on code in the VelocityServlet shipped with Velocity. Exposes the following JavaBean properties:

  • templateName: name of the Velocity template to be cached
  • poolSize (optional, default=40): number of Velocity writers (refer to Velocity documentation to see exactly what this means)
  • cache: whether or not Velocity templates should be cached. They always should be in production (the default), but setting this to false enables us to modify Velocity templates without restarting the application
  • exposeDateFormatter: whether to expose a DateFormatter helper object in the Velocity context. Defaults to false, as it creates an object that is only needed if we do date formatting. Velocity is currently weak in this area.
  • exposeCurrencyFormatter: whether to expose a CurrencyFormatter helper object.

    Author:
    Rod Johnson

    Field Summary
    static java.lang.String CURRENCY_FORMAT_KEY
              Helper context name
    static java.lang.String DATE_FORMAT_KEY
              Helper context name
    static java.lang.String DEFAULT_OUTPUT_ENCODING
              Encoding for the output stream
     
    Fields inherited from class com.interface21.context.support.ApplicationObjectSupport
    logger
     
    Constructor Summary
    VelocityView()
              Creates new VelocityView
     
    Method Summary
     boolean getCache()
               
     boolean getExposeCurrencyFormatter()
              Gets the exposeCurrencyFormatter.
     boolean getExposeDateFormatter()
              Gets the exposeDateFormatter.
     int getPoolSize()
               
    protected  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
              Render the view given the model to output.
     void setCache(boolean cache)
               
     void setExposeCurrencyFormatter(boolean exposeCurrencyFormatter)
              Sets the exposeCurrencyFormatter.
     void setExposeDateFormatter(boolean exposeDateFormatter)
              Sets the exposeDateFormatter.
     void setPoolSize(int sz)
               
     void setTemplateName(java.lang.String templateName)
              Set the name of the wrapped Velocity template.
     
    Methods inherited from class com.interface21.web.servlet.view.AbstractView
    addStaticAttribute, getContentType, getName, getStaticAttributes, render, setAttributes, setAttributesCSV, setContentType, setName, setRequestContextAttribute
     
    Methods inherited from class com.interface21.context.support.ApplicationObjectSupport
    getApplicationContext, initApplicationContext, setApplicationContext
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    DATE_FORMAT_KEY

    public static final java.lang.String DATE_FORMAT_KEY
    Helper context name

    CURRENCY_FORMAT_KEY

    public static final java.lang.String CURRENCY_FORMAT_KEY
    Helper context name

    DEFAULT_OUTPUT_ENCODING

    public static final java.lang.String DEFAULT_OUTPUT_ENCODING
    Encoding for the output stream
    Constructor Detail

    VelocityView

    public VelocityView()
    Creates new VelocityView
    Method Detail

    setPoolSize

    public void setPoolSize(int sz)

    getPoolSize

    public int getPoolSize()

    getCache

    public boolean getCache()

    setCache

    public void setCache(boolean cache)

    getExposeDateFormatter

    public boolean getExposeDateFormatter()
    Gets the exposeDateFormatter.
    Returns:
    Returns a boolean

    setExposeDateFormatter

    public void setExposeDateFormatter(boolean exposeDateFormatter)
    Sets the exposeDateFormatter.
    Parameters:
    exposeDateFormatter - The exposeDateFormatter to set

    getExposeCurrencyFormatter

    public boolean getExposeCurrencyFormatter()
    Gets the exposeCurrencyFormatter.
    Returns:
    Returns a boolean

    setExposeCurrencyFormatter

    public void setExposeCurrencyFormatter(boolean exposeCurrencyFormatter)
    Sets the exposeCurrencyFormatter.
    Parameters:
    exposeCurrencyFormatter - The exposeCurrencyFormatter to set

    setTemplateName

    public void setTemplateName(java.lang.String templateName)
                         throws javax.servlet.ServletException
    Set the name of the wrapped Velocity template. This will cause the template to be loaded.
    Parameters:
    templateName - the name of the wrapped Velocity template, relative to the Velocity template root. For example, "/ic/interestResult.vm".

    renderMergedOutputModel

    protected void renderMergedOutputModel(java.util.Map model,
                                           javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response)
                                    throws javax.servlet.ServletException
    Render the view given the model to output.
    Overrides:
    renderMergedOutputModel in class AbstractView
    Parameters:
    model - combined output Map, with dynamic values taking precedence over static attributes
    request - HttpServetRequest
    response - HttpServletResponse
    Throws:
    javax.servlet.ServletException - if there is any other error


    Rod Johnson and Spring contributors 2001-2003.