Top Description Methods
org.springframework.web.servlet

public Interface LocaleContextResolver

extends LocaleResolver
Known Direct Implementers
org.springframework.web.servlet.i18n.AbstractLocaleContextResolver
Imports
java.util.Locale, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.context.i18n.LocaleContext, .SimpleLocaleContext, org.springframework.lang.Nullable

Extension of LocaleResolver that adds support for a rich locale context (potentially including locale and time zone information).

Also provides default implementations of resolveLocale and setLocale which delegate to resolveLocaleContext and setLocaleContext, respectively.

Authors
Juergen Hoeller, Sam Brannen
Since
4.0
See Also
org.springframework.context.i18n.LocaleContext, org.springframework.context.i18n.TimeZoneAwareLocaleContext, org.springframework.context.i18n.LocaleContextHolder, org.springframework.web.servlet.support.RequestContext#getTimeZone, org.springframework.web.servlet.support.RequestContextUtils#getTimeZone

Method Summary

Modifier and TypeMethod and Description
public default Locale

Returns:

the current locale (never null)
resolveLocale
(HttpServletRequest
the request to resolve the locale for
request
)

Implements org.springframework.web.servlet.LocaleResolver.resolveLocale.

Default implementation of LocaleResolver#resolveLocale(HttpServletRequest) that delegates to resolveLocaleContext(HttpServletRequest), falling back to HttpServletRequest#getLocale() if necessary.

public LocaleContext

Returns:

the current locale context (never null
resolveLocaleContext
(HttpServletRequest
the request to resolve the locale context for
request
)

Resolve the current locale context via the given request.

public default void
setLocale(HttpServletRequest
the request to be used for locale modification
request
,
HttpServletResponse
the response to be used for locale modification
response
,
Locale
the new locale, or null to clear the locale
locale
)

Implements org.springframework.web.servlet.LocaleResolver.setLocale.

Default implementation of LocaleResolver#setLocale(HttpServletRequest, HttpServletResponse, Locale) that delegates to setLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using a SimpleLocaleContext.

public void
setLocaleContext(HttpServletRequest
the request to be used for locale modification
request
,
HttpServletResponse
the response to be used for locale modification
response
,
LocaleContext
the new locale context, or null to clear the locale
localeContext
)

Set the current locale context to the given one, potentially including a locale with associated time zone information.

Method Detail

resolveLocaleback to summary
public default Locale resolveLocale(HttpServletRequest request)

Implements org.springframework.web.servlet.LocaleResolver.resolveLocale.

Default implementation of LocaleResolver#resolveLocale(HttpServletRequest) that delegates to resolveLocaleContext(HttpServletRequest), falling back to HttpServletRequest#getLocale() if necessary.

Parameters
request:HttpServletRequest

the request to resolve the locale for

Returns:Locale

the current locale (never null)

Annotations
@Override
Since
6.0
resolveLocaleContextback to summary
public LocaleContext resolveLocaleContext(HttpServletRequest request)

Resolve the current locale context via the given request.

This is primarily intended for framework-level processing; consider using org.springframework.web.servlet.support.RequestContextUtils or org.springframework.web.servlet.support.RequestContext for application-level access to the current locale and/or time zone.

The returned context may be a org.springframework.context.i18n.TimeZoneAwareLocaleContext, containing a locale with associated time zone information. Simply apply an instanceof check and downcast accordingly.

Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting.

Parameters
request:HttpServletRequest

the request to resolve the locale context for

Returns:LocaleContext

the current locale context (never null

See Also
resolveLocale(HttpServletRequest), org.springframework.web.servlet.support.RequestContextUtils#getLocale, org.springframework.web.servlet.support.RequestContextUtils#getTimeZone
setLocaleback to summary
public default void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)

Implements org.springframework.web.servlet.LocaleResolver.setLocale.

Default implementation of LocaleResolver#setLocale(HttpServletRequest, HttpServletResponse, Locale) that delegates to setLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using a SimpleLocaleContext.

Parameters
request:HttpServletRequest

the request to be used for locale modification

response:HttpServletResponse

the response to be used for locale modification

locale:Locale

the new locale, or null to clear the locale

Annotations
@Override
Exceptions
UnsupportedOperationException:
if the LocaleResolver implementation does not support dynamic changing of the locale
Since
6.0
setLocaleContextback to summary
public void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext)

Set the current locale context to the given one, potentially including a locale with associated time zone information.

Parameters
request:HttpServletRequest

the request to be used for locale modification

response:HttpServletResponse

the response to be used for locale modification

localeContext:LocaleContext

the new locale context, or null to clear the locale

Exceptions
UnsupportedOperationException:
if the LocaleResolver implementation does not support dynamic changing of the locale or time zone
See Also
setLocale(HttpServletRequest, HttpServletResponse, Locale), org.springframework.context.i18n.SimpleLocaleContext, org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext