Class SessionLocaleResolver
- All Implemented Interfaces:
LocaleResolver
When a locale has been explicitly stored in the session via setLocale(Locale),
this resolver returns that locale. Otherwise it returns null, allowing a
CompositeLocaleResolver to fall through to the next resolver (typically
AcceptLanguageLocaleResolver).
This resolver enables the common pattern where users select a preferred language in their profile or settings, which then takes precedence over the browser's Accept-Language header for subsequent requests.
Usage:
// Set the user's preferred locale (e.g., from a language selector)
SessionLocaleResolver.setLocale(Locale.GERMANY);
// Retrieve the session locale (null if not explicitly set)
Locale sessionLocale = SessionLocaleResolver.getLocale();
// Clear the override (revert to Accept-Language detection)
SessionLocaleResolver.clearLocale();
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidRemoves the locale override from the current session.static LocaleReturns the locale stored in the current session.resolveLocale(OorianHttpRequest request) Resolves the locale from the current session.static voidStores a locale override in the current session.
-
Constructor Details
-
SessionLocaleResolver
public SessionLocaleResolver()Creates a new session-based locale resolver.
-
-
Method Details
-
resolveLocale
Resolves the locale from the current session.Returns the locale stored in the session attribute, or
nullif no locale has been explicitly set viasetLocale(Locale).- Specified by:
resolveLocalein interfaceLocaleResolver- Parameters:
request- the current HTTP request- Returns:
- the session locale, or
nullif none is stored
-
setLocale
Stores a locale override in the current session.Once set, the
SessionLocaleResolverwill return this locale for all subsequent requests in the same session, until it is cleared viaclearLocale().- Parameters:
locale- the locale to store in the session
-
getLocale
Returns the locale stored in the current session.- Returns:
- the session locale, or
nullif none has been set
-
clearLocale
public static void clearLocale()Removes the locale override from the current session.After clearing, locale resolution will fall through to the next resolver in the chain (typically Accept-Language detection).
-