org.codehaus.groovy.grails.web.servlet.view
Class GroovyPageView

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.codehaus.groovy.grails.web.servlet.view.GroovyPageView
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.View

public class GroovyPageView
extends org.springframework.web.servlet.view.AbstractUrlBasedView

A Spring View that renders Groovy Server Pages to the response. It requires an instance of GroovyPagesTemplateEngine to be set and will render to view returned by the getUrl() method of AbstractUrlBasedView This view also requires an instance of GrailsWebRequest to be bound to the currently executing Thread using Spring's RequestContextHolder. This can be done with by adding the GrailsWebRequestFilter.

Since:
0.4
See Also:
AbstractUrlBasedView.getUrl(), GroovyPagesTemplateEngine, GrailsWebRequestFilter, RequestContextHolder

Field Summary
static java.lang.String EXCEPTION_MODEL_KEY
           
protected  groovy.text.Template template
           
protected  GroovyPagesTemplateEngine templateEngine
           
 
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
GroovyPageView()
           
 
Method Summary
 void afterPropertiesSet()
           
static GroovyPagesException createGroovyPageException(java.lang.Exception exception, GroovyPagesTemplateEngine engine, java.lang.String pageUrl)
           
protected  GSPResponseWriter createResponseWriter(javax.servlet.http.HttpServletResponse response)
          Creates the Response Writer for the specified HttpServletResponse instance.
protected  void handleException(java.lang.Exception exception, GroovyPagesTemplateEngine engine)
          Performs exception handling by attempting to render the Errors view.
protected  void initTemplate()
           
 boolean isExpired()
           
protected  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Delegates to renderMergedOutputModel(..)
protected  void renderWithTemplateEngine(GroovyPagesTemplateEngine engine, java.util.Map model, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request)
          Renders a page with the specified TemplateEngine, mode and response.
 void setScriptSource(org.springframework.scripting.ScriptSource scriptSource)
           
 void setTemplateEngine(GroovyPagesTemplateEngine templateEngine)
           
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
checkResource, 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, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

templateEngine

protected GroovyPagesTemplateEngine templateEngine

template

protected groovy.text.Template template

EXCEPTION_MODEL_KEY

public static final java.lang.String EXCEPTION_MODEL_KEY
See Also:
Constant Field Values
Constructor Detail

GroovyPageView

public GroovyPageView()
Method Detail

renderMergedOutputModel

protected final void renderMergedOutputModel(java.util.Map model,
                                             javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response)
                                      throws java.lang.Exception
Delegates to renderMergedOutputModel(..)

Specified by:
renderMergedOutputModel in class org.springframework.web.servlet.view.AbstractView
Parameters:
model - The view model
request - The HttpServletRequest
response - The HttpServletResponse
Throws:
java.lang.Exception - When an error occurs rendering the view
See Also:
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

renderWithTemplateEngine

protected void renderWithTemplateEngine(GroovyPagesTemplateEngine engine,
                                        java.util.Map model,
                                        javax.servlet.http.HttpServletResponse response,
                                        javax.servlet.http.HttpServletRequest request)
                                 throws java.io.IOException
Renders a page with the specified TemplateEngine, mode and response.

Parameters:
engine - The TemplateEngine to use
model - The model to use
response - The HttpServletResponse instance
request - The HttpServletRequest
Throws:
java.io.IOException - Thrown when an error occurs writing the response

handleException

protected void handleException(java.lang.Exception exception,
                               GroovyPagesTemplateEngine engine)
Performs exception handling by attempting to render the Errors view.

Parameters:
exception - The exception that occured
engine - The GSP engine

createGroovyPageException

public static GroovyPagesException createGroovyPageException(java.lang.Exception exception,
                                                             GroovyPagesTemplateEngine engine,
                                                             java.lang.String pageUrl)

createResponseWriter

protected GSPResponseWriter createResponseWriter(javax.servlet.http.HttpServletResponse response)
Creates the Response Writer for the specified HttpServletResponse instance.

Parameters:
response - The HttpServletResponse instance
Returns:
A response Writer

setTemplateEngine

public void setTemplateEngine(GroovyPagesTemplateEngine templateEngine)

isExpired

public boolean isExpired()

setScriptSource

public void setScriptSource(org.springframework.scripting.ScriptSource scriptSource)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Overrides:
afterPropertiesSet in class org.springframework.web.servlet.view.AbstractUrlBasedView
Throws:
java.lang.Exception

initTemplate

protected void initTemplate()
                     throws java.io.IOException
Throws:
java.io.IOException