Suitable for exposition to views, and usage within JSP's "useBean" tag, JSP scriptlets, JSTL EL, etc. Necessary for views that do not have access to the servlet request, like FreeMarker templates.
Can be instantiated manually, or automatically exposed to views as model attribute via AbstractView's "requestContextAttribute" property.
Will also work outside DispatcherServlet requests, accessing the root WebApplicationContext and using an appropriate fallback for the locale (the HttpServletRequest's primary locale).
org.springframework.web.servlet.DispatcherServlet , org.springframework.web.servlet.view.AbstractView#setRequestContextAttribute , org.springframework.web.servlet.view.UrlBasedViewResolver#setRequestContextAttribute
| Modifier and Type | Class and Description |
|---|---|
| private static class | RequestContext.
Inner class that isolates the JSTL dependency. |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | DEFAULT_THEME_NAME
Deprecated
since 6.0. as of 6.0, with no direct replacement
Default theme name used if the RequestContext cannot find a ThemeResolver.
|
| private Boolean | |
| private Map | |
| protected static final boolean | |
| private Locale | |
| private final Map | |
| private final HttpServletRequest | |
| private RequestDataValueProcessor | |
| private final HttpServletResponse | |
| private final Boolean | |
| private Theme | theme
Deprecated
|
| private TimeZone | |
| private UrlPathHelper | |
| public static final String | WEB_APPLICATION_CONTEXT_ATTRIBUTE
Request attribute to hold the current web application context for RequestContext usage. |
| private final WebApplicationContext |
| Access | Constructor and Description |
|---|---|
| public | RequestContext(HttpServletRequest
current HTTP request request)Create a new RequestContext for the given request, using the request attributes for Errors retrieval. |
| public | RequestContext(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response)Create a new RequestContext for the given request, using the request attributes for Errors retrieval. |
| public | RequestContext(HttpServletRequest
current HTTP request request, ServletContext the servlet context of the web application (can be servletContext)null;
necessary for fallback to root WebApplicationContext)Create a new RequestContext for the given request, using the request attributes for Errors retrieval. |
| public | RequestContext(HttpServletRequest
current HTTP request request, Map<String, Object> the model attributes for the current view (can be model)null,
using the request attributes for Errors retrieval)Create a new RequestContext for the given request, using the given model attributes for Errors retrieval. |
| public | RequestContext(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, ServletContext the servlet context of the web application (can be servletContext, Map<String, Object> null; necessary for
fallback to root WebApplicationContext)the model attributes for the current view (can be model)null, using the request attributes
for Errors retrieval)Create a new RequestContext for the given request, using the given model attributes for Errors retrieval. |
| Modifier and Type | Method and Description |
|---|---|
| public void | changeLocale(Locale
the new locale locale)Change the current locale to the specified one,
storing the new locale through the configured |
| public void | changeLocale(Locale
the new locale locale, TimeZone the new time zone timeZone)Change the current locale to the specified locale and time zone context,
storing the new locale context through the configured |
| public void | changeTheme(Theme
the new theme theme)
Deprecated
since 6.0. as of 6.0, with no direct replacement
Change the current theme to the specified one,
storing the new theme name through the configured
|
| public void | changeTheme(String
the name of the new theme themeName)
Deprecated
as of 6.0, with no direct replacement
Change the current theme to the specified theme by name,
storing the new theme name through the configured
|
| public BindStatus | Returns: the new BindStatus instancethe bean and property path for which values and errors will be resolved (e.g. "person.age") path)Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting. |
| public BindStatus | Returns: the new BindStatus instancethe bean and property path for which values and errors will be resolved (e.g. "person.age") path, boolean create a BindStatus with automatic HTML escaping? htmlEscape)Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting. |
| public String | getContextPath()
Return the context path of the original request, that is, the path that indicates the current web application. |
| public String | Returns: a URL that points back to the server with an absolute path (also URL-encoded accordingly)the relative URL part relativeUrl)Return a context-aware URl for the given relative URL. |
| public String | Returns: a URL that points back to the server with an absolute path (also URL-encoded accordingly)the relative URL part relativeUrl, Map<String, ?> a map of parameters to insert as placeholders in the url params)Return a context-aware URl for the given relative URL with placeholders (named keys with braces |
| public Boolean | Returns: whether default HTML escaping is enabled (null = no explicit default)Return the default HTML escape setting, differentiating between no default specified and an explicit value. |
| public Errors | |
| public Errors | |
| protected Locale | Returns: the fallback locale (nevernull)Determine the fallback locale for this context. |
| protected Theme | Returns: the fallback theme (nevernull)
Deprecated
as of 6.0, with no direct replacement
Determine the fallback theme for this context. |
| protected TimeZone | Returns: the fallback time zone (ornull if none derivable from the request)Determine the fallback time zone for this context. |
| public final Locale | |
| public String | Returns: the messagethe code of the message code, String the String to return if the lookup fails defaultMessage)Retrieve the message for the given code, using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe code of the message code, Object[] arguments for the message, or args, String null if nonethe String to return if the lookup fails defaultMessage)Retrieve the message for the given code, using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe code of the message code, List<?> arguments for the message as a List, or args, String null if nonethe String to return if the lookup fails defaultMessage)Retrieve the message for the given code, using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe code of the message code, Object[] arguments for the message, or args, String null if nonethe String to return if the lookup fails defaultMessage, boolean if the message should be HTML-escaped htmlEscape)Retrieve the message for the given code. |
| public String | Returns: the messagethe code of the message code)Retrieve the message for the given code, using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe code of the message code, Object[] arguments for the message, or args)null if noneRetrieve the message for the given code, using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe code of the message code, List<?> arguments for the message as a List, or args)null if noneRetrieve the message for the given code, using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe code of the message code, Object[] arguments for the message, or args, boolean null if noneif the message should be HTML-escaped htmlEscape)Retrieve the message for the given code. |
| public String | Returns: the messagethe MessageSourceResolvable resolvable)Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance), using the "defaultHtmlEscape" setting. |
| public String | Returns: the messagethe MessageSourceResolvable resolvable, boolean if the message should be HTML-escaped htmlEscape)Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance). |
| public final MessageSource | |
| public final Map | Returns: the populated model Map, ornull if none availableReturn the model Map that this RequestContext encapsulates, if any. |
| protected Object | Returns: the model objectthe name of the model object modelName)Retrieve the model object for the given model name, either from the model or from the request attributes. |
| public String | getPathToServlet()
Return the path to URL mappings within the current servlet including the context path and the servlet path of the original request. |
| public String | getQueryString()
Return the query string of the current request, that is, the part after the request path. |
| protected final HttpServletRequest | |
| public RequestDataValueProcessor | getRequestDataValueProcessor()
Return the RequestDataValueProcessor instance to use obtained from the
WebApplicationContext under the name |
| public String | getRequestUri()
Return the request URI of the original request, that is, the invoked URL without parameters. |
| public Boolean | Returns: whether default use of response encoding HTML escaping is enabled (null = no explicit default)Return the default setting about use of response encoding for HTML escape setting, differentiating between no default specified and an explicit value. |
| protected final ServletContext | |
| public Theme | getTheme()
Deprecated
since 6.0. as of 6.0, with no direct replacement
Return the current theme (never |
| public String | Returns: the messagethe code of the message code, String the String to return if the lookup fails defaultMessage)
Deprecated
as of 6.0, with no direct replacement
Retrieve the theme message for the given code. |
| public String | Returns: the messagethe code of the message code, Object[] arguments for the message, or args, String null if nonethe String to return if the lookup fails defaultMessage)
Deprecated
as of 6.0, with no direct replacement
Retrieve the theme message for the given code. |
| public String | Returns: the messagethe code of the message code, List<?> arguments for the message as a List, or args, String null if nonethe String to return if the lookup fails defaultMessage)
Deprecated
as of 6.0, with no direct replacement
Retrieve the theme message for the given code. |
| public String | Returns: the messagethe code of the message code)
Deprecated
as of 6.0, with no direct replacement
Retrieve the theme message for the given code. |
| public String | Returns: the messagethe code of the message code, Object[] arguments for the message, or args)null if none
Deprecated
as of 6.0, with no direct replacement
Retrieve the theme message for the given code. |
| public String | Returns: the messagethe code of the message code, List<?> arguments for the message as a List, or args)null if none
Deprecated
as of 6.0, with no direct replacement
Retrieve the theme message for the given code. |
| public String | Returns: the messagethe MessageSourceResolvable resolvable)
Deprecated
as of 6.0, with no direct replacement
Retrieve the given MessageSourceResolvable in the current theme. |
| public TimeZone | |
| public UrlPathHelper | |
| public final WebApplicationContext | |
| public boolean | |
| public boolean | |
| public void | setDefaultHtmlEscape(boolean defaultHtmlEscape)
(De)activate default HTML escaping for messages and errors, for the scope of this RequestContext. |
| public void | setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for context path and request URI decoding. |