java.lang.Object | |
↳ | org.springframework.web.servlet.support.RequestContext |
Known Direct Subclasses |
Context holder for request-specific state, like current web application context, current locale, current theme, and potential binding errors. Provides easy access to localized messages and Errors instances.
Suitable for exposition to views, and usage within JSP's "useBean" tag, JSP scriptlets, JSTL EL, Velocity templates, etc. Necessary for views that do not have access to the servlet request, like Velocity templates.
Can be instantiated manually, or automatically exposed to views as model attribute via AbstractView's "requestContextAttribute" property.
Will also work outside of DispatcherServlet requests, accessing the root WebApplicationContext and using an appropriate fallback for the locale (the HttpServletRequest's primary locale).
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEFAULT_THEME_NAME | Default theme name used if the RequestContext cannot find a ThemeResolver. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
WEB_APPLICATION_CONTEXT_ATTRIBUTE | Request attribute to hold the current web application context for RequestContext usage. | ||||||||||
jstlPresent |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new RequestContext for the given request,
using the request attributes for Errors retrieval.
| |||||||||||
Create a new RequestContext for the given request,
using the request attributes for Errors retrieval.
| |||||||||||
Create a new RequestContext for the given request,
using the given model attributes for Errors retrieval.
| |||||||||||
Create a new RequestContext for the given request,
using the given model attributes for Errors retrieval.
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Default constructor for subclasses.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a BindStatus for the given bind object,
using the "defaultHtmlEscape" setting.
| |||||||||||
Create a BindStatus for the given bind object,
using the "defaultHtmlEscape" setting.
| |||||||||||
Return the context path of the original request,
that is, the path that indicates the current web application.
| |||||||||||
Return a context-aware URl for the given relative URL.
| |||||||||||
Return the default HTML escape setting, differentiating
between no default specified and an explicit value.
| |||||||||||
Retrieve the Errors instance for the given bind object,
using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the Errors instance for the given bind object.
| |||||||||||
Return the current Locale (never
null ). | |||||||||||
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the message for the given code.
| |||||||||||
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
| |||||||||||
Retrieve the given MessageSourceResolvable (e.g.
| |||||||||||
Retrieve the message for the given code.
| |||||||||||
Retrieve the given MessageSourceResolvable (e.g.
| |||||||||||
Return the current WebApplicationContext as MessageSource.
| |||||||||||
Return the model Map that this RequestContext encapsulates, if any.
| |||||||||||
Return the query string of the current request, that is, the part after
the request path.
| |||||||||||
Return the request URI of the original request, that is, the invoked URL
without parameters.
| |||||||||||
Return the current theme (never
null ). | |||||||||||
Retrieve the theme message for the given code.
| |||||||||||
Retrieve the theme message for the given code.
| |||||||||||
Retrieve the theme message for the given code.
| |||||||||||
Retrieve the theme message for the given code.
| |||||||||||
Retrieve the theme message for the given code.
| |||||||||||
Retrieve the theme message for the given code.
| |||||||||||
Retrieve the given MessageSourceResolvable in the current theme.
| |||||||||||
Return the UrlPathHelper used for context path and request URI decoding.
| |||||||||||
Return the current WebApplicationContext.
| |||||||||||
Is default HTML escaping active?
Falls back to
false in case of no explicit default given. | |||||||||||
(De)activate default HTML escaping for messages and errors, for the scope
of this RequestContext.
| |||||||||||
Set the UrlPathHelper to use for context path and request URI decoding.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Determine the fallback locale for this context.
| |||||||||||
Determine the fallback theme for this context.
| |||||||||||
Retrieve the model object for the given model name,
either from the model or from the request attributes.
| |||||||||||
Return the underlying HttpServletRequest.
| |||||||||||
Return the underlying ServletContext.
| |||||||||||
Initialize this context with the given request,
using the given model attributes for Errors retrieval.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Default theme name used if the RequestContext cannot find a ThemeResolver. Only applies to non-DispatcherServlet requests.
Same as AbstractThemeResolver's default, but not linked in here to avoid package interdependencies.
Request attribute to hold the current web application context for RequestContext usage. By default, the DispatcherServlet's context (or the root context as fallback) is exposed.
Create a new RequestContext for the given request, using the request attributes for Errors retrieval.
This only works with InternalResourceViews, as Errors instances are part of the model and not normally exposed as request attributes. It will typically be used within JSPs or custom tags.
Will only work within a DispatcherServlet request. Pass in a ServletContext to be able to fallback to the root WebApplicationContext.
request | current HTTP request |
---|
Create a new RequestContext for the given request, using the request attributes for Errors retrieval.
This only works with InternalResourceViews, as Errors instances are part of the model and not normally exposed as request attributes. It will typically be used within JSPs or custom tags.
If a ServletContext is specified, the RequestContext will also work with the root WebApplicationContext (outside a DispatcherServlet).
request | current HTTP request |
---|---|
servletContext | the servlet context of the web application
(can be null ; necessary for fallback to root WebApplicationContext) |
Create a new RequestContext for the given request, using the given model attributes for Errors retrieval.
This works with all View implementations. It will typically be used by View implementations.
Will only work within a DispatcherServlet request. Pass in a ServletContext to be able to fallback to the root WebApplicationContext.
request | current HTTP request |
---|---|
model | the model attributes for the current view
(can be null , using the request attributes for Errors retrieval) |
DispatcherServlet
Create a new RequestContext for the given request, using the given model attributes for Errors retrieval.
This works with all View implementations. It will typically be used by View implementations.
If a ServletContext is specified, the RequestContext will also work with a root WebApplicationContext (outside a DispatcherServlet).
request | current HTTP request |
---|---|
response | current HTTP response |
servletContext | the servlet context of the web application
(can be null ; necessary for fallback to root WebApplicationContext) |
model | the model attributes for the current view
(can be null , using the request attributes for Errors retrieval) |
Default constructor for subclasses.
Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting.
path | the bean and property path for which values and errors will be resolved (e.g. "person.age") |
---|---|
htmlEscape | create a BindStatus with automatic HTML escaping? |
IllegalStateException | if no corresponding Errors object found |
---|
Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting.
path | the bean and property path for which values and errors will be resolved (e.g. "person.age") |
---|
IllegalStateException | if no corresponding Errors object found |
---|
Return the context path of the original request, that is, the path that indicates the current web application. This is useful for building links to other resources within the application.
Delegates to the UrlPathHelper for decoding.
Return a context-aware URl for the given relative URL.
relativeUrl | the relative URL part |
---|
Return the default HTML escape setting, differentiating between no default specified and an explicit value.
Retrieve the Errors instance for the given bind object, using the "defaultHtmlEscape" setting.
name | name of the bind object |
---|
null
if not found
Retrieve the Errors instance for the given bind object.
name | name of the bind object |
---|---|
htmlEscape | create an Errors instance with automatic HTML escaping? |
null
if not found
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
code | code of the message |
---|---|
defaultMessage | String to return if the lookup fails |
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
code | code of the message |
---|---|
args | arguments for the message, or null if none |
NoSuchMessageException | if not found |
---|
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
code | code of the message |
---|
NoSuchMessageException | if not found |
---|
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
code | code of the message |
---|---|
args | arguments for the message as a List, or null if none |
NoSuchMessageException | if not found |
---|
Retrieve the message for the given code.
code | code of the message |
---|---|
args | arguments for the message, or null if none |
htmlEscape | HTML escape the message? |
NoSuchMessageException | if not found |
---|
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
code | code of the message |
---|---|
args | arguments for the message, or null if none |
defaultMessage | String to return if the lookup fails |
Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
code | code of the message |
---|---|
args | arguments for the message as a List, or null if none |
defaultMessage | String to return if the lookup fails |
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance).
resolvable | the MessageSourceResolvable |
---|---|
htmlEscape | HTML escape the message? |
NoSuchMessageException | if not found |
---|
Retrieve the message for the given code.
code | code of the message |
---|---|
args | arguments for the message, or null if none |
defaultMessage | String to return if the lookup fails |
htmlEscape | HTML escape the message? |
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance), using the "defaultHtmlEscape" setting.
resolvable | the MessageSourceResolvable |
---|
NoSuchMessageException | if not found |
---|
Return the current WebApplicationContext as MessageSource.
Return the model Map that this RequestContext encapsulates, if any.
null
if none available
Return the query string of the current request, that is, the part after the request path. This is particularly useful for building an HTML form action target in combination with the original request URI.
Note this implementation will correctly resolve to the query string of any originating root request in the presence of a forwarded request. However, this can only work when the Servlet 2.4 'forward' request attributes are present.
Delegates to the UrlPathHelper for decoding.
Return the request URI of the original request, that is, the invoked URL without parameters. This is particularly useful as HTML form action target, possibly in combination with the original query string.
Note this implementation will correctly resolve to the URI of any originating root request in the presence of a forwarded request. However, this can only work when the Servlet 2.4 'forward' request attributes are present.
Delegates to the UrlPathHelper for decoding.
Return the current theme (never null
).
Resolved lazily for more efficiency when theme support is not being used.
Retrieve the theme message for the given code.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
code | code of the message |
---|---|
args | arguments for the message as a List, or null if none |
defaultMessage | String to return if the lookup fails |
Retrieve the theme message for the given code.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
code | code of the message |
---|---|
args | arguments for the message, or null if none |
defaultMessage | String to return if the lookup fails |
Retrieve the theme message for the given code.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
code | code of the message |
---|---|
args | arguments for the message, or null if none |
NoSuchMessageException | if not found |
---|
Retrieve the theme message for the given code.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
code | code of the message |
---|---|
defaultMessage | String to return if the lookup fails |
Retrieve the theme message for the given code.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
code | code of the message |
---|
NoSuchMessageException | if not found |
---|
Retrieve the theme message for the given code.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
code | code of the message |
---|---|
args | arguments for the message as a List, or null if none |
NoSuchMessageException | if not found |
---|
Retrieve the given MessageSourceResolvable in the current theme.
Note that theme messages are never HTML-escaped, as they typically denote theme-specific resource paths and not client-visible messages.
resolvable | the MessageSourceResolvable |
---|
NoSuchMessageException | if not found |
---|
Return the UrlPathHelper used for context path and request URI decoding. Can be used to configure the current UrlPathHelper.
A default UrlPathHelper is always available.
Return the current WebApplicationContext.
Is default HTML escaping active?
Falls back to false
in case of no explicit default given.
(De)activate default HTML escaping for messages and errors, for the scope of this RequestContext. The default is the application-wide setting (the "defaultHtmlEscape" context-param in web.xml).
Set the UrlPathHelper to use for context path and request URI decoding. Can be used to pass a shared UrlPathHelper instance in.
A default UrlPathHelper is always available.
Determine the fallback locale for this context.
The default implementation checks for a JSTL locale attribute
in request, session or application scope; if not found,
returns the HttpServletRequest.getLocale()
.
null
)Determine the fallback theme for this context.
The default implementation returns the default theme (with name "theme").
null
)
Retrieve the model object for the given model name, either from the model or from the request attributes.
modelName | the name of the model object |
---|
Return the underlying HttpServletRequest. Only intended for cooperating classes in this package.
Return the underlying ServletContext. Only intended for cooperating classes in this package.
Initialize this context with the given request, using the given model attributes for Errors retrieval.
Delegates to getFallbackLocale
and getFallbackTheme
for determining the fallback locale and theme, respectively, if no LocaleResolver
and/or ThemeResolver can be found in the request.
request | current HTTP request |
---|---|
servletContext | the servlet context of the web application
(can be null ; necessary for fallback to root WebApplicationContext) |
model | the model attributes for the current view
(can be null , using the request attributes for Errors retrieval) |