Top Description Inners Constructors Methods
org.springframework.web.servlet.support

public abstract Class JstlUtils

extends Object
Class Inheritance
Imports
java.util.Locale, .ResourceBundle, .TimeZone, jakarta.servlet.ServletContext, jakarta.servlet.http.HttpServletRequest, .HttpSession, jakarta.servlet.jsp.jstl.core.Config, jakarta.servlet.jsp.jstl.fmt.LocalizationContext, org.springframework.context.MessageSource, org.springframework.context.support.MessageSourceResourceBundle, .ResourceBundleMessageSource, org.springframework.lang.Nullable

Helper class for preparing JSTL views, in particular for exposing a JSTL localization context.
Author
Juergen Hoeller
Since
20.08.2003

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
JstlUtils.SpringLocalizationContext

Spring-specific LocalizationContext adapter that merges session-scoped JSTL LocalizationContext/Locale attributes with the local Spring request context.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
exposeLocalizationContext(HttpServletRequest
the current HTTP request
request
,
MessageSource
the MessageSource to expose, typically the current ApplicationContext (may be null)
messageSource
)

Exposes JSTL-specific request attributes specifying locale and resource bundle for JSTL's formatting and message tags, using Spring's locale and MessageSource.

public static void
exposeLocalizationContext(RequestContext
the context for the current HTTP request, including the ApplicationContext to expose as MessageSource
requestContext
)

Exposes JSTL-specific request attributes specifying locale and resource bundle for JSTL's formatting and message tags, using Spring's locale and MessageSource.

public static MessageSource

Returns:

the MessageSource to expose to JSTL; first checking the JSTL-defined bundle, then the Spring-defined MessageSource
getJstlAwareMessageSource
(ServletContext
the ServletContext we're running in (to check JSTL-related context-params in web.xml)
servletContext
,
MessageSource
the MessageSource to expose, typically the ApplicationContext of the current DispatcherServlet
messageSource
)

Checks JSTL's "jakarta.servlet.jsp.jstl.fmt.localizationContext" context-param and creates a corresponding child message source, with the provided Spring-defined MessageSource as parent.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

JstlUtilsback to summary
public JstlUtils()

Method Detail

exposeLocalizationContextback to summary
public static void exposeLocalizationContext(HttpServletRequest request, MessageSource messageSource)

Exposes JSTL-specific request attributes specifying locale and resource bundle for JSTL's formatting and message tags, using Spring's locale and MessageSource.

Parameters
request:HttpServletRequest

the current HTTP request

messageSource:MessageSource

the MessageSource to expose, typically the current ApplicationContext (may be null)

See Also
exposeLocalizationContext(RequestContext)
exposeLocalizationContextback to summary
public static void exposeLocalizationContext(RequestContext requestContext)

Exposes JSTL-specific request attributes specifying locale and resource bundle for JSTL's formatting and message tags, using Spring's locale and MessageSource.

Parameters
requestContext:RequestContext

the context for the current HTTP request, including the ApplicationContext to expose as MessageSource

getJstlAwareMessageSourceback to summary
public static MessageSource getJstlAwareMessageSource(ServletContext servletContext, MessageSource messageSource)

Checks JSTL's "jakarta.servlet.jsp.jstl.fmt.localizationContext" context-param and creates a corresponding child message source, with the provided Spring-defined MessageSource as parent.

Parameters
servletContext:ServletContext

the ServletContext we're running in (to check JSTL-related context-params in web.xml)

messageSource:MessageSource

the MessageSource to expose, typically the ApplicationContext of the current DispatcherServlet

Returns:MessageSource

the MessageSource to expose to JSTL; first checking the JSTL-defined bundle, then the Spring-defined MessageSource

See Also
org.springframework.context.ApplicationContext
org.springframework.web.servlet.support back to summary

private Class JstlUtils.SpringLocalizationContext

extends LocalizationContext
Class Inheritance

Spring-specific LocalizationContext adapter that merges session-scoped JSTL LocalizationContext/Locale attributes with the local Spring request context.

Field Summary

Modifier and TypeField and Description
private final MessageSource
private final HttpServletRequest

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Locale
getLocale()

Overrides jakarta.servlet.jsp.jstl.fmt.LocalizationContext.getLocale.

Gets the locale of this I18N localization context.

public ResourceBundle
getResourceBundle()

Overrides jakarta.servlet.jsp.jstl.fmt.LocalizationContext.getResourceBundle.

Gets the resource bundle of this I18N localization context.

Field Detail

messageSourceback to summary
private final MessageSource messageSource
requestback to summary
private final HttpServletRequest request

Constructor Detail

SpringLocalizationContextback to summary
public SpringLocalizationContext(MessageSource messageSource, HttpServletRequest request)

Method Detail

getLocaleback to summary
public Locale getLocale()

Overrides jakarta.servlet.jsp.jstl.fmt.LocalizationContext.getLocale.

Doc from jakarta.servlet.jsp.jstl.fmt.LocalizationContext.getLocale.

Gets the locale of this I18N localization context.

Returns:Locale

The locale of this I18N localization context, or null if this I18N localization context is empty, or its resource bundle is a (locale-less) root resource bundle.

Annotations
@Override
getResourceBundleback to summary
public ResourceBundle getResourceBundle()

Overrides jakarta.servlet.jsp.jstl.fmt.LocalizationContext.getResourceBundle.

Doc from jakarta.servlet.jsp.jstl.fmt.LocalizationContext.getResourceBundle.

Gets the resource bundle of this I18N localization context.

Returns:ResourceBundle

The resource bundle of this I18N localization context, or null if this I18N localization context is empty

Annotations
@Override