Interface LocaleContextResolver
- All Superinterfaces:
- LocaleResolver
- All Known Implementing Classes:
- AbstractLocaleContextResolver, CookieLocaleResolver, FixedLocaleResolver, SessionLocaleResolver
LocaleResolver that adds support for a rich locale context
(potentially including locale and time zone information).
Also provides default implementations of resolveLocale(HttpServletRequest) and
setLocale(HttpServletRequest, HttpServletResponse, Locale) which delegate to resolveLocaleContext(HttpServletRequest) and
setLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), respectively.
- Since:
- 4.0
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptiondefault LocaleresolveLocale(jakarta.servlet.http.HttpServletRequest request) Default implementation ofLocaleResolver.resolveLocale(HttpServletRequest)that delegates toresolveLocaleContext(HttpServletRequest), falling back toServletRequest.getLocale()if necessary.resolveLocaleContext(jakarta.servlet.http.HttpServletRequest request) Resolve the current locale context via the given request.default voidsetLocale(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable Locale locale) Default implementation ofLocaleResolver.setLocale(HttpServletRequest, HttpServletResponse, Locale)that delegates tosetLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using aSimpleLocaleContext.voidsetLocaleContext(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable LocaleContext localeContext) Set the current locale context to the given one, potentially including a locale with associated time zone information.
- 
Method Details- 
resolveLocaleContextResolve the current locale context via the given request.This is primarily intended for framework-level processing; consider using RequestContextUtilsorRequestContextfor application-level access to the current locale and/or time zone.The returned context may be a TimeZoneAwareLocaleContext, containing a locale with associated time zone information. Simply apply aninstanceofcheck and downcast accordingly.Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting. - Parameters:
- request- the request to resolve the locale context for
- Returns:
- the current locale context (never null
- See Also:
 
- 
setLocaleContextvoid setLocaleContext(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable LocaleContext localeContext) Set the current locale context to the given one, potentially including a locale with associated time zone information.- Parameters:
- request- the request to be used for locale modification
- response- the response to be used for locale modification
- localeContext- the new locale context, or- nullto clear the locale
- Throws:
- UnsupportedOperationException- if the LocaleResolver implementation does not support dynamic changing of the locale or time zone
- See Also:
 
- 
resolveLocaleDefault implementation ofLocaleResolver.resolveLocale(HttpServletRequest)that delegates toresolveLocaleContext(HttpServletRequest), falling back toServletRequest.getLocale()if necessary.- Specified by:
- resolveLocalein interface- LocaleResolver
- Parameters:
- request- the request to resolve the locale for
- Returns:
- the current locale (never null)
- Since:
- 6.0
 
- 
setLocaledefault void setLocale(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable Locale locale) Default implementation ofLocaleResolver.setLocale(HttpServletRequest, HttpServletResponse, Locale)that delegates tosetLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using aSimpleLocaleContext.- Specified by:
- setLocalein interface- LocaleResolver
- Parameters:
- request- the request to be used for locale modification
- response- the response to be used for locale modification
- locale- the new locale, or- nullto clear the locale
- Throws:
- UnsupportedOperationException- if the LocaleResolver implementation does not support dynamic changing of the locale
- Since:
- 6.0
 
 
-