public class

CookieThemeResolver

extends CookieGenerator
implements ThemeResolver
java.lang.Object
   ↳ org.springframework.web.util.CookieGenerator
     ↳ org.springframework.web.servlet.theme.CookieThemeResolver

Class Overview

Implementation of ThemeResolver that uses a cookie sent back to the user in case of a custom setting, with a fallback to the default theme. This is particularly useful for stateless applications without user sessions.

Custom controllers can thus override the user's theme by calling setThemeName, e.g. responding to a certain theme change request.

Summary

Constants
String ORIGINAL_DEFAULT_THEME_NAME
[Expand]
Inherited Constants
From class org.springframework.web.util.CookieGenerator
Fields
public static final String DEFAULT_COOKIE_NAME
public static final String THEME_REQUEST_ATTRIBUTE_NAME Name of the request attribute that holds the theme name.
[Expand]
Inherited Fields
From class org.springframework.web.util.CookieGenerator
Public Constructors
CookieThemeResolver()
Public Methods
String getDefaultThemeName()
Return the name of the default theme.
String resolveThemeName(HttpServletRequest request)
Resolve the current theme name via the given request.
void setDefaultThemeName(String defaultThemeName)
Set the name of the default theme.
void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName)
Set the current theme name to the given one.
[Expand]
Inherited Methods
From class org.springframework.web.util.CookieGenerator
From class java.lang.Object
From interface org.springframework.web.servlet.ThemeResolver

Constants

public static final String ORIGINAL_DEFAULT_THEME_NAME

Constant Value: "theme"

Fields

public static final String DEFAULT_COOKIE_NAME

public static final String THEME_REQUEST_ATTRIBUTE_NAME

Name of the request attribute that holds the theme name. Only used for overriding a cookie value if the theme has been changed in the course of the current request! Use RequestContext.getTheme() to retrieve the current theme in controllers or views.

See Also

Public Constructors

public CookieThemeResolver ()

Public Methods

public String getDefaultThemeName ()

Return the name of the default theme.

public String resolveThemeName (HttpServletRequest request)

Resolve the current theme name via the given request. Should return a default theme as fallback in any case.

Parameters
request request to be used for resolution
Returns
  • the current theme name

public void setDefaultThemeName (String defaultThemeName)

Set the name of the default theme.

public void setThemeName (HttpServletRequest request, HttpServletResponse response, String themeName)

Set the current theme name to the given one.

Parameters
request request to be used for theme name modification
response response to be used for theme name modification
themeName the new theme name