org.springframework.web.servlet.view.tiles
Class TilesView

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.view.AbstractView
              extended byorg.springframework.web.servlet.view.AbstractUrlBasedView
                  extended byorg.springframework.web.servlet.view.InternalResourceView
                      extended byorg.springframework.web.servlet.view.tiles.TilesView
All Implemented Interfaces:
ApplicationContextAware, BeanNameAware, View
Direct Known Subclasses:
TilesJstlView

public class TilesView
extends InternalResourceView

View implementation that retrieves a Tiles definition. The "url" property is interpreted as name of a Tiles definition.

TilesJstlView with JSTL support is a separate class, mainly to avoid JSTL dependencies in this class.

Depends on a Tiles DefinitionsFactory which must be available in the ServletContext. This factory is typically set up via a TilesConfigurer bean definition in the application context.

A component controller specified in the Tiles definition will receive a reference to the current Spring ApplicationContext if it implements ApplicationContextAware. The ComponentControllerSupport class provides a convenient base class for such Spring-aware component controllers.

Author:
Alef Arendsen, Juergen Hoeller
See Also:
AbstractUrlBasedView.setUrl(java.lang.String), TilesJstlView, TilesConfigurer, ComponentControllerSupport, ApplicationContextAware

Field Summary
static String PATH_ATTRIBUTE
          Name of the attribute that will override the path of the layout page to render.
 
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
TilesView()
           
 
Method Summary
protected  void executeController(Controller controller, ComponentContext context, HttpServletRequest request, HttpServletResponse response)
          Execute the given Tiles controller.
protected  ComponentContext getComponentContext(ComponentDefinition definition, HttpServletRequest request)
          Determine the Tiles component context for the given Tiles definition.
protected  ComponentDefinition getComponentDefinition(DefinitionsFactory factory, HttpServletRequest request)
          Determine the Tiles component definition for the given Tiles definitions factory.
protected  Controller getController(ComponentDefinition definition, HttpServletRequest request)
          Determine and initialize the Tiles component controller for the given Tiles definition, if any.
protected  String getDispatcherPath(ComponentDefinition definition, HttpServletRequest request)
          Determine the dispatcher path for the given Tiles definition, i.e. the request dispatcher path of the layout page.
protected  void initApplicationContext()
          Overridden lifecycle method to check that 'url' property is set.
protected  String prepareForRendering(HttpServletRequest request, HttpServletResponse response)
          Prepare for rendering the Tiles definition: Execute the associated component controller if any, and determine the request dispatcher path.
static void setPath(HttpServletRequest request, String path)
          Set the path of the layout page to render.
 
Methods inherited from class org.springframework.web.servlet.view.InternalResourceView
exposeHelpers, exposeModelAsRequestAttributes, renderMergedOutputModel, useInclude
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
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
 

Field Detail

PATH_ATTRIBUTE

public static final String PATH_ATTRIBUTE
Name of the attribute that will override the path of the layout page to render. A Tiles component controller can set such an attribute to dynamically switch the look and feel of a Tiles page.

See Also:
setPath(javax.servlet.http.HttpServletRequest, java.lang.String)
Constructor Detail

TilesView

public TilesView()
Method Detail

setPath

public static void setPath(HttpServletRequest request,
                           String path)
Set the path of the layout page to render.

Parameters:
request - current HTTP request
path - the path of the layout page
See Also:
PATH_ATTRIBUTE

initApplicationContext

protected void initApplicationContext()
                               throws ApplicationContextException
Description copied from class: AbstractUrlBasedView
Overridden lifecycle method to check that 'url' property is set.

Overrides:
initApplicationContext in class AbstractUrlBasedView
Throws:
ApplicationContextException

prepareForRendering

protected String prepareForRendering(HttpServletRequest request,
                                     HttpServletResponse response)
                              throws Exception
Prepare for rendering the Tiles definition: Execute the associated component controller if any, and determine the request dispatcher path.

Overrides:
prepareForRendering in class InternalResourceView
Parameters:
request - current HTTP request
response - current HTTP response
Returns:
the request dispatcher path to use
Throws:
Exception - if preparations failed
See Also:
AbstractUrlBasedView.getUrl(), prepareForRendering(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

getComponentDefinition

protected ComponentDefinition getComponentDefinition(DefinitionsFactory factory,
                                                     HttpServletRequest request)
                                              throws Exception
Determine the Tiles component definition for the given Tiles definitions factory.

Parameters:
factory - the Tiles definitions factory
request - current HTTP request
Returns:
the component definition
Throws:
Exception

getComponentContext

protected ComponentContext getComponentContext(ComponentDefinition definition,
                                               HttpServletRequest request)
                                        throws Exception
Determine the Tiles component context for the given Tiles definition.

Parameters:
definition - the Tiles definition to render
request - current HTTP request
Returns:
the component context
Throws:
Exception - if preparations failed

getController

protected Controller getController(ComponentDefinition definition,
                                   HttpServletRequest request)
                            throws Exception
Determine and initialize the Tiles component controller for the given Tiles definition, if any.

Parameters:
definition - the Tiles definition to render
request - current HTTP request
Returns:
the component controller to execute, or null if none
Throws:
Exception - if preparations failed

executeController

protected void executeController(Controller controller,
                                 ComponentContext context,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
                          throws Exception
Execute the given Tiles controller.

Parameters:
controller - the component controller to execute
context - the component context
request - current HTTP request
response - current HTTP response
Throws:
Exception - if controller execution failed

getDispatcherPath

protected String getDispatcherPath(ComponentDefinition definition,
                                   HttpServletRequest request)
                            throws Exception
Determine the dispatcher path for the given Tiles definition, i.e. the request dispatcher path of the layout page.

Parameters:
definition - the Tiles definition to render
request - current HTTP request
Returns:
the path of the layout page to render
Throws:
Exception - if preparations failed


Copyright (C) 2003-2004 The Spring Framework Project.