Class CookieThemeResolver

All Implemented Interfaces:

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.

Jean-Pierre Pawlak, Juergen Hoeller
See Also:
  • Field Details


      public static final String ORIGINAL_DEFAULT_THEME_NAME
      The default theme name used if no alternative is provided.
      See Also:

      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:
  • Constructor Details

    • CookieThemeResolver

      public CookieThemeResolver()
  • Method Details

    • setDefaultThemeName

      public void setDefaultThemeName(String defaultThemeName)
      Set the name of the default theme.
    • getDefaultThemeName

      public String getDefaultThemeName()
      Return the name of the default theme.
    • resolveThemeName

      public String resolveThemeName(HttpServletRequest request)
      Description copied from interface: ThemeResolver
      Resolve the current theme name via the given request. Should return a default theme as fallback in any case.
      Specified by:
      resolveThemeName in interface ThemeResolver
      request - the request to be used for resolution
      the current theme name
    • setThemeName

      public void setThemeName(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable String themeName)
      Description copied from interface: ThemeResolver
      Set the current theme name to the given one.
      Specified by:
      setThemeName in interface ThemeResolver
      request - the request to be used for theme name modification
      response - the response to be used for theme name modification
      themeName - the new theme name (null or empty to reset it)