org.thymeleaf.spring3.view
Class ThymeleafView

Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.thymeleaf.spring3.view.ThymeleafView
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.View

public class ThymeleafView
extends org.springframework.web.context.support.WebApplicationObjectSupport
implements org.springframework.web.servlet.View, org.springframework.beans.factory.BeanNameAware

Implementation of the Spring MVC View interface.

Views represent a template being executed, after being resolved (and instantiated) by a ViewResolver.

This is the view implementation resolved by ThymeleafViewResolver.

Since:
1.0
Author:
Daniel Fernández, Josh Long

Field Summary
static String DEFAULT_CONTENT_TYPE
           Default charset set to ISO-8859-1 for compatibility reasons with Spring's AbstractView.
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Fields inherited from interface org.springframework.web.servlet.View
RESPONSE_STATUS_ATTRIBUTE
 
Constructor Summary
protected ThymeleafView()
           Creates a new instance of ThymeleafView.
protected ThymeleafView(String templateName)
           Creates a new instance of ThymeleafView, specifying the template name.
 
Method Summary
 void addStaticVariable(String name, Object value)
           Add a new static variable.
 String getBeanName()
           Returns the bean name.
 String getCharacterEncoding()
           Returns the character encoding set to be used for rendering this view.
 String getContentType()
           Returns the content type that will used for this view.
protected  Locale getLocale()
           Returns the locale to be used for template processing.
 Map<String,Object> getStaticVariables()
           Return the static variables, which will be available at the context every time this view is processed.
protected  SpringTemplateEngine getTemplateEngine()
           Returns the template engine instance –a SpringTemplateEngine instance, specifically– to be used for processing the template specified by this view object.
 String getTemplateName()
           Returns the name of the template being processed by this view object.
 void render(Map<String,?> model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void setBeanName(String beanName)
           Sets the bean name.
 void setCharacterEncoding(String characterEncoding)
           Specifies the character encoding to be set into the response when the view is rendered.
 void setContentType(String contentType)
           Sets the content type that will used for this view.
 void setStaticVariables(Map<String,?> variables)
           Sets a set of static variables, which will be available at the context when this view is processed.
 void setTemplateName(String templateName)
           Sets the name of the template to be processed by this view object.
 String toString()
           
 
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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE

public static final String DEFAULT_CONTENT_TYPE

Default charset set to ISO-8859-1 for compatibility reasons with Spring's AbstractView. Value is "text/html;charset=ISO-8859-1".

See Also:
Constant Field Values
Constructor Detail

ThymeleafView

protected ThymeleafView()

Creates a new instance of ThymeleafView.


ThymeleafView

protected ThymeleafView(String templateName)

Creates a new instance of ThymeleafView, specifying the template name.

Parameters:
templateName - the template name.
Method Detail

getContentType

public String getContentType()

Returns the content type that will used for this view.

Content type will be computed this way:

Specified by:
getContentType in interface org.springframework.web.servlet.View
Returns:
the content type
See Also:
ThymeleafViewResolver.getContentType()

setContentType

public void setContentType(String contentType)

Sets the content type that will used for this view.

Content type will be computed this way:

Parameters:
contentType - the content type to be used.
See Also:
ThymeleafViewResolver.setContentType(String)

getCharacterEncoding

public String getCharacterEncoding()

Returns the character encoding set to be used for rendering this view.

Many times, character encoding is specified as a part of the content type using the setContentType(String) method, but this is not mandatory, and it could be that only the MIME type is specified that way, thus allowing to set the character encoding using the setCharacterEncoding(String) counterpart of this getter method.

Returns:
the character encoding to be set.

setCharacterEncoding

public void setCharacterEncoding(String characterEncoding)

Specifies the character encoding to be set into the response when the view is rendered.

Many times, character encoding is specified as a part of the content type using the setContentType(String) method, but this is not mandatory, and it could be that only the MIME type is specified that way, thus allowing to set the character encoding using the setCharacterEncoding(String) counterpart of this getter method.

Parameters:
characterEncoding - the character encoding to be used (e.g. UTF-8, ISO-8859-1, etc.)

getBeanName

public String getBeanName()

Returns the bean name.

Returns:
the bean name.

setBeanName

public void setBeanName(String beanName)

Sets the bean name.

Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware
Parameters:
beanName - the new bean name.

getTemplateName

public String getTemplateName()

Returns the name of the template being processed by this view object.

This name will be specified in the same shape it will be resolved by the template resolvers (i.e. as it is returned by controllers, without any prefixes/suffixes).

Returns:
the template name.

setTemplateName

public void setTemplateName(String templateName)

Sets the name of the template to be processed by this view object.

This name will be specified in the same shape it will be resolved by the template resolvers (i.e. as it is returned by controllers, without any prefixes/suffixes).

Parameters:
templateName - the template name

getLocale

protected Locale getLocale()

Returns the locale to be used for template processing.

Returns:
the locale

getTemplateEngine

protected SpringTemplateEngine getTemplateEngine()

Returns the template engine instance –a SpringTemplateEngine instance, specifically– to be used for processing the template specified by this view object.

Returns:
the template engine instance

getStaticVariables

public Map<String,Object> getStaticVariables()

Return the static variables, which will be available at the context every time this view is processed.

These static variables are added to the context before the view is processed, so that they can be referenced from the context like any other context variables, for example: ${myStaticVar}.

Returns:
the map of static variables to be set into view's execution.

addStaticVariable

public void addStaticVariable(String name,
                              Object value)

Add a new static variable.

These static variables are added to the context before this view is processed, so that they can be referenced from the context like any other context variables, for example: ${myStaticVar}.

Parameters:
name - the name of the static variable
value - the value of the static variable

setStaticVariables

public void setStaticVariables(Map<String,?> variables)

Sets a set of static variables, which will be available at the context when this view is processed.

This method does not overwrite the existing static variables, it simply adds the ones specify to any variables already registered.

These static variables are added to the context before this view is processed, so that they can be referenced from the context like any other context variables, for example: ${myStaticVar}.

Parameters:
variables - the set of variables to be added.

render

public void render(Map<String,?> model,
                   javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws Exception
Specified by:
render in interface org.springframework.web.servlet.View
Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012 The THYMELEAF team. All Rights Reserved.