org.springbyexample.web.servlet.view.tiles2
Class DynamicTilesView

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.springbyexample.web.servlet.view.tiles2.DynamicTilesView
All Implemented Interfaces:
BeanNameAware, InitializingBean, ApplicationContextAware, ServletContextAware, View

public class DynamicTilesView
extends AbstractUrlBasedView

View implementation that first checks if the request is a Tiles definition, then if it isn't tries to retrieve a default Tiles template and uses the url to dynamically set the body.

The main template name defaults to 'mainTemplate', the body attribute defaults to to 'body', and the delimiter is '.' which is used for replacing a '/' in the url.

If a request is made for '/info/index.html', Spring will pass 'info/index' into the view. The first thing will be to look for 'info/index' as a Tiles definition. Then a template definition of '.info.mainTemplate', which if found will dynamically have a body set on this definition. If the previous aren't found, it is assumed a root definition exists. This would be '.mainTemplate'. If none of these exist, a TilesException will be thrown.

  1. Check if a Tiles definition based on the URL matches.
  2. Checks if a definition derived from the URL and default template name exists and then dynamically insert the body based on the URL.
  3. Check if there is a root template definition and then dynamically insert the body based on the URL.
  4. If no match is found from any process above a TilesException is thrown.

Author:
David Winterfeldt

Field Summary
 
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
DynamicTilesView()
           
 
Method Summary
protected  void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
          Renders output using Tiles.
 void setTilesBodyAttributeName(String tilesBodyAttributeName)
          Tiles body attribute name.
 void setTilesDefinitionDelimiter(String tilesDefinitionDelimiter)
          Sets Tiles definition delimiter.
 void setTilesDefinitionName(String tilesDefinitionName)
          Main template name.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
afterPropertiesSet, getUrl, isUrlRequired, setUrl, toString
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, 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
 

Constructor Detail

DynamicTilesView

public DynamicTilesView()
Method Detail

setTilesDefinitionName

public void setTilesDefinitionName(String tilesDefinitionName)
Main template name. The default is 'mainTemplate'.

Parameters:
tilesDefinitionName - Main template name used to lookup definitions.

setTilesBodyAttributeName

public void setTilesBodyAttributeName(String tilesBodyAttributeName)
Tiles body attribute name. The default is 'body'.

Parameters:
tilesBodyAttributeName - Tiles body attribute name.

setTilesDefinitionDelimiter

public void setTilesDefinitionDelimiter(String tilesDefinitionDelimiter)
Sets Tiles definition delimiter. For example, instead of using the request 'info/about' to lookup the template definition 'info/mainTemplate', the default delimiter of '.' would look for '.info.mainTemplate'

Parameters:
tilesDefinitionDelimiter - Optional delimiter to replace '/' in a url.

renderMergedOutputModel

protected void renderMergedOutputModel(Map model,
                                       HttpServletRequest request,
                                       HttpServletResponse response)
                                throws Exception
Renders output using Tiles.

Specified by:
renderMergedOutputModel in class AbstractView
Throws:
Exception


Copyright © 2008 Spring by Example. All Rights Reserved.