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 String |
DEFAULT_COOKIE_NAME
The default name of the cookie that holds the theme name.
|
static String |
ORIGINAL_DEFAULT_THEME_NAME
The default theme name used if no alternative is provided.
|
static 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 |
---|---|
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.
|
addCookie, createCookie, getCookieDomain, getCookieMaxAge, getCookieName, getCookiePath, isCookieHttpOnly, isCookieSecure, removeCookie, setCookieDomain, setCookieHttpOnly, setCookieMaxAge, setCookieName, setCookiePath, setCookieSecure
public static final String ORIGINAL_DEFAULT_THEME_NAME
public static final String THEME_REQUEST_ATTRIBUTE_NAME
RequestContext.getTheme()
public static final String DEFAULT_COOKIE_NAME
public void setDefaultThemeName(String defaultThemeName)
public String getDefaultThemeName()
public String resolveThemeName(HttpServletRequest request)
ThemeResolver
resolveThemeName
in interface ThemeResolver
request
- request to be used for resolutionpublic void setThemeName(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable 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)