org.springframework.web.servlet.theme

## Class SessionThemeResolver

- java.lang.Object
- - org.springframework.web.servlet.theme.AbstractThemeResolver
  - - org.springframework.web.servlet.theme.SessionThemeResolver

- All Implemented Interfaces:
    ThemeResolver

      public class SessionThemeResolver
      extends AbstractThemeResolver

  Implementation of ThemeResolver 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.

  Since:
    17.06.2003
  Author:
    Jean-Pierre Pawlak, Juergen Hoeller
  See Also:
    `setThemeName(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `THEME_SESSION_ATTRIBUTE_NAME` Name of the session attribute that holds the theme name.

    - ### Fields inherited from class org.springframework.web.servlet.theme.AbstractThemeResolver

      `ORIGINAL_DEFAULT_THEME_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SessionThemeResolver()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `resolveThemeName(HttpServletRequest request)` Resolve the current theme name via the given request.
    `void` | `setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName)` Set the current theme name to the given one.

    - ### Methods inherited from class org.springframework.web.servlet.theme.AbstractThemeResolver

      `getDefaultThemeName, setDefaultThemeName`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### THEME_SESSION_ATTRIBUTE_NAME

          public static final String THEME_SESSION_ATTRIBUTE_NAME

      Name of the session attribute that holds the theme name. Only used internally by this implementation. Use `RequestContext(Utils).getTheme()` to retrieve the current theme in controllers or views.
      See Also:
        `RequestContext.getTheme()`, `RequestContextUtils.getTheme(javax.servlet.http.HttpServletRequest)`

  - ### Constructor Detail

    - #### SessionThemeResolver

          public SessionThemeResolver()

  - ### Method Detail

    - #### 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.
      Parameters:
        `request` - request to be used for resolution
      Returns:
        the current theme name

    - #### setThemeName

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

      Description copied from interface: `ThemeResolver`
      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