public class SessionLocaleResolver extends AbstractLocaleResolver
This is most appropriate if the application needs user sessions anyway, that is, when the HttpSession does not have to be created for the locale.
Custom controllers can override the user's locale by calling
setLocale
, e.g. responding to a locale change request.
AbstractLocaleResolver.setDefaultLocale(java.util.Locale)
,
setLocale(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Locale)
Modifier and Type | Field and Description |
---|---|
static String |
LOCALE_SESSION_ATTRIBUTE_NAME
Name of the session attribute that holds the locale.
|
Constructor and Description |
---|
SessionLocaleResolver() |
Modifier and Type | Method and Description |
---|---|
protected Locale |
determineDefaultLocale(HttpServletRequest request)
Determine the default locale for the given request,
Called if no locale session attribute has been found.
|
Locale |
resolveLocale(HttpServletRequest request)
Resolve the current locale via the given request.
|
void |
setLocale(HttpServletRequest request,
HttpServletResponse response,
Locale locale)
Set the current locale to the given one.
|
getDefaultLocale, setDefaultLocale
public static final String LOCALE_SESSION_ATTRIBUTE_NAME
RequestContext(Utils).getLocale()
to retrieve the current locale in controllers or views.public Locale resolveLocale(HttpServletRequest request)
LocaleResolver
request
- the request to resolve the locale fornull
)protected Locale determineDefaultLocale(HttpServletRequest request)
The default implementation returns the specified default locale, if any, else falls back to the request's accept-header locale.
request
- the request to resolve the locale fornull
)AbstractLocaleResolver.setDefaultLocale(java.util.Locale)
,
ServletRequest.getLocale()
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)
LocaleResolver
request
- the request to be used for locale modificationresponse
- the response to be used for locale modificationlocale
- the new locale, or null
to clear the locale