public class SessionThemeResolver extends AbstractThemeResolver
ThemeResolver
implementation that
uses a theme attribute in the user's session in case of a custom setting,
with a fallback to the default theme. This is most appropriate if the
application needs user sessions anyway.
Custom controllers can override the user's theme by calling
setThemeName
, e.g. responding to a 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 |
THEME_SESSION_ATTRIBUTE_NAME
Name of the session attribute that holds the theme name.
|
ORIGINAL_DEFAULT_THEME_NAME
Constructor and Description |
---|
SessionThemeResolver() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
resolveThemeName(HttpServletRequest request)
Resolve the current theme name via the given request.
|
void |
setThemeName(HttpServletRequest request,
HttpServletResponse response,
java.lang.String themeName)
Set the current theme name to the given one.
|
getDefaultThemeName, setDefaultThemeName
public static final java.lang.String THEME_SESSION_ATTRIBUTE_NAME
RequestContext(Utils).getTheme()
to retrieve the current theme in controllers or views.public java.lang.String resolveThemeName(HttpServletRequest request)
ThemeResolver
request
- request to be used for resolutionpublic void setThemeName(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable java.lang.String themeName)
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)