public class CookieThemeResolver extends CookieGenerator implements ThemeResolver
ThemeResolver
implementation 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.
setThemeName(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_COOKIE_NAME |
static java.lang.String |
ORIGINAL_DEFAULT_THEME_NAME |
static java.lang.String |
THEME_REQUEST_ATTRIBUTE_NAME
Name of the request attribute that holds the theme name.
|
DEFAULT_COOKIE_PATH, logger
Constructor and Description |
---|
CookieThemeResolver() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDefaultThemeName()
Return the name of the default theme.
|
java.lang.String |
resolveThemeName(HttpServletRequest request)
Resolve the current theme name via the given request.
|
void |
setDefaultThemeName(java.lang.String defaultThemeName)
Set the name of the default theme.
|
void |
setThemeName(HttpServletRequest request,
HttpServletResponse response,
java.lang.String themeName)
Set the current theme name to the given one.
|
addCookie, createCookie, getCookieDomain, getCookieMaxAge, getCookieName, getCookiePath, isCookieHttpOnly, isCookieSecure, removeCookie, setCookieDomain, setCookieHttpOnly, setCookieMaxAge, setCookieName, setCookiePath, setCookieSecure
public static final java.lang.String ORIGINAL_DEFAULT_THEME_NAME
public static final java.lang.String THEME_REQUEST_ATTRIBUTE_NAME
RequestContext.getTheme()
public static final java.lang.String DEFAULT_COOKIE_NAME
public void setDefaultThemeName(java.lang.String defaultThemeName)
public java.lang.String getDefaultThemeName()
public java.lang.String resolveThemeName(HttpServletRequest request)
ThemeResolver
resolveThemeName
in interface ThemeResolver
request
- request to be used for resolutionpublic void setThemeName(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable java.lang.String themeName)
ThemeResolver
setThemeName
in interface ThemeResolver
request
- request to be used for theme name modificationresponse
- response to be used for theme name modificationthemeName
- the new theme name (null
or empty to reset it)