org.thymeleaf.spring4.view
Class AbstractThymeleafView

Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.thymeleaf.spring4.view.AbstractThymeleafView
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.View
Direct Known Subclasses:
ThymeleafView

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

Abstract implementation class of the Spring MVC View interface for Thymeleaf.

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

Since:
2.0.11
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
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
 
Constructor Summary
protected AbstractThymeleafView()
           Creates a new instance of ThymeleafView.
protected AbstractThymeleafView(String templateName)
           Creates a new instance of ThymeleafView, specifying the template name.
 
Method Summary
protected static void addRequestContextAsVariable(Map<String,Object> model, String variableName, org.springframework.web.servlet.support.RequestContext requestContext)
           
 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.
protected  boolean isContentTypeSet()
           
 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.
protected  void setLocale(Locale locale)
           Sets the locale to be used for template processing.
 void setStaticVariables(Map<String,?> variables)
           Sets a set of static variables, which will be available at the context when this view is processed.
protected  void setTemplateEngine(SpringTemplateEngine templateEngine)
           Sets the template engine instance –a SpringTemplateEngine instance, specifically– to be used for processing the template specified by this view object.
 void setTemplateName(String templateName)
           Sets the name of the template to be processed by this view object.
 
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, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.web.servlet.View
render
 

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

AbstractThymeleafView

protected AbstractThymeleafView()

Creates a new instance of ThymeleafView.


AbstractThymeleafView

protected AbstractThymeleafView(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)

isContentTypeSet

protected boolean isContentTypeSet()

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.

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

setLocale

protected void setLocale(Locale locale)

Sets the locale to be used for template processing. Usually, the View Resolver will set this automatically from user session / application data.

Parameters:
locale - the locale to be used.

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

setTemplateEngine

protected void setTemplateEngine(SpringTemplateEngine templateEngine)

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

Parameters:
templateEngine - the template engine instance to be used

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.

addRequestContextAsVariable

protected static void addRequestContextAsVariable(Map<String,Object> model,
                                                  String variableName,
                                                  org.springframework.web.servlet.support.RequestContext requestContext)
                                           throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException


Copyright © 2013 The THYMELEAF team. All Rights Reserved.