| java.lang.Object org.springframework.web.servlet.support.RequestContext
All known Subclasses: org.springframework.web.servlet.support.JspAwareRequestContext,
RequestContext | public class RequestContext (Code) | | 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 DispatcherServlet requests, accessing the root
WebApplicationContext and using an appropriate fallback for the locale
(the JSTL locale if available, or the HttpServletRequest locale else).
author: Juergen Hoeller since: 03.03.2003 See Also: org.springframework.web.servlet.DispatcherServlet See Also: org.springframework.web.servlet.view.AbstractView.setRequestContextAttribute See Also: org.springframework.web.servlet.view.UrlBasedViewResolver.setRequestContextAttribute See Also: RequestContext.getFallbackLocale |
Method Summary | |
public BindStatus | getBindStatus(String path) Create a BindStatus for the given bind object,
using the "defaultHtmlEscape" setting.
Parameters: path - the bean and property path for which values and errorswill be resolved (e.g. | public BindStatus | getBindStatus(String path, boolean htmlEscape) Create a BindStatus for the given bind object,
using the "defaultHtmlEscape" setting.
Parameters: path - the bean and property path for which values and errorswill be resolved (e.g. | public String | getContextPath() Return the context path of the original request,
that is, the path that indicates the current web application. | public Errors | getErrors(String name) Retrieve the Errors instance for the given bind object,
using the "defaultHtmlEscape" setting. | public Errors | getErrors(String name, boolean htmlEscape) Retrieve the Errors instance for the given bind object. | protected Locale | getFallbackLocale() Determine the fallback locale for this context. | protected Theme | getFallbackTheme() Determine the fallback theme for this context. | final public Locale | getLocale() Return the current locale. | public String | getMessage(String code, String defaultMessage) Retrieve the message for the given code, using the "defaultHtmlEscape" setting. | public String | getMessage(String code, Object[] args, String defaultMessage) Retrieve the message for the given code, using the "defaultHtmlEscape" setting. | public String | getMessage(String code, List args, String defaultMessage) Retrieve the message for the given code, using the "defaultHtmlEscape" setting. | public String | getMessage(String code, Object[] args, String defaultMessage, boolean htmlEscape) Retrieve the message for the given code. | public String | getMessage(String code) Retrieve the message for the given code, using the "defaultHtmlEscape" setting. | public String | getMessage(String code, Object[] args) Retrieve the message for the given code, using the "defaultHtmlEscape" setting. | public String | getMessage(String code, List args) Retrieve the message for the given code, using the "defaultHtmlEscape" setting. | public String | getMessage(String code, Object[] args, boolean htmlEscape) Retrieve the message for the given code. | public String | getMessage(MessageSourceResolvable resolvable) Retrieve the given MessageSourceResolvable (e.g. | public String | getMessage(MessageSourceResolvable resolvable, boolean htmlEscape) Retrieve the given MessageSourceResolvable (e.g. | protected Object | getModelObject(String modelName) Retrieve the model object for the given model name,
either from the model or from the request attributes. | public String | getQueryString() Return the query string of the current request, that is, the part after
the request path. | final protected HttpServletRequest | getRequest() Return the underlying HttpServletRequest. | public String | getRequestUri() Return the request URI of the original request, that is, the invoked URL
without parameters. | final protected ServletContext | getServletContext() Return the underlying ServletContext. | final public Theme | getTheme() Return the current theme. | public String | getThemeMessage(String code, String defaultMessage) Retrieve the theme message for the given code. | public String | getThemeMessage(String code, Object[] args, String defaultMessage) Retrieve the theme message for the given code. | public String | getThemeMessage(String code, List args, String defaultMessage) Retrieve the theme message for the given code. | public String | getThemeMessage(String code) Retrieve the theme message for the given code. | public String | getThemeMessage(String code, Object[] args) Retrieve the theme message for the given code. | public String | getThemeMessage(String code, List args) Retrieve the theme message for the given code. | public String | getThemeMessage(MessageSourceResolvable resolvable) Retrieve the given MessageSourceResolvable in the current theme. | public UrlPathHelper | getUrlPathHelper() Return the UrlPathHelper used for context path and request URI decoding. | final public WebApplicationContext | getWebApplicationContext() Return the current WebApplicationContext. | protected void | initContext(HttpServletRequest request, ServletContext servletContext, Map model) Initialize this context with the given request,
using the given model attributes for Errors retrieval. | public boolean | isDefaultHtmlEscape() | 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. |
APPLICATION_SCOPE_SUFFIX | final protected static String APPLICATION_SCOPE_SUFFIX(Code) | | JSTL suffix for application-scoped attributes
|
DEFAULT_THEME | final public static Theme DEFAULT_THEME(Code) | | Default (empty) Theme used if the RequestContext cannot find a ThemeSource.
|
JSTL_LOCALE_ATTRIBUTE | final public static String JSTL_LOCALE_ATTRIBUTE(Code) | | JSTL locale attribute, as used by JSTL implementations to expose their
current locale. Used as fallback in non-DispatcherServlet requests; if not
available, the accept-header locale is used (request.getLocale Same as the FMT_LOCALE constant in JSTL's Config class, but not linked
in here to avoid a hard-coded dependency on JSTL. RequestContext does not
depend on JSTL except for this fallback check of JSTL's locale attribute.
See Also: javax.servlet.jsp.jstl.core.Config.FMT_LOCALE See Also: javax.servlet.http.HttpServletRequest.getLocale |
REQUEST_SCOPE_SUFFIX | final protected static String REQUEST_SCOPE_SUFFIX(Code) | | JSTL suffix for request-scoped attributes
|
SESSION_SCOPE_SUFFIX | final protected static String SESSION_SCOPE_SUFFIX(Code) | | JSTL suffix for session-scoped attributes
|
RequestContext | public RequestContext(HttpServletRequest request, ServletContext servletContext)(Code) | | 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).
Parameters: request - current HTTP request Parameters: servletContext - the servlet context of the web application(can be null ; necessary for fallback to root WebApplicationContext) See Also: org.springframework.web.context.WebApplicationContext See Also: org.springframework.web.servlet.DispatcherServlet |
RequestContext | public RequestContext(HttpServletRequest request, ServletContext servletContext, Map model)(Code) | | 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).
Parameters: request - current HTTP request Parameters: servletContext - the servlet context of the web application(can be null ; necessary for fallback to root WebApplicationContext) Parameters: model - the model attributes for the current view(can be null , using the request attributes for Errors retrieval) See Also: org.springframework.web.context.WebApplicationContext See Also: org.springframework.web.servlet.DispatcherServlet |
RequestContext | protected RequestContext()(Code) | | Default constructor for subclasses.
|
getBindStatus | public BindStatus getBindStatus(String path) throws IllegalStateException(Code) | | Create a BindStatus for the given bind object,
using the "defaultHtmlEscape" setting.
Parameters: path - the bean and property path for which values and errorswill be resolved (e.g. "person.age") the new BindStatus instance throws: IllegalStateException - if no corresponding Errors object found |
getBindStatus | public BindStatus getBindStatus(String path, boolean htmlEscape) throws IllegalStateException(Code) | | Create a BindStatus for the given bind object,
using the "defaultHtmlEscape" setting.
Parameters: path - the bean and property path for which values and errorswill be resolved (e.g. "person.age") Parameters: htmlEscape - create a BindStatus with automatic HTML escaping? the new BindStatus instance throws: IllegalStateException - if no corresponding Errors object found |
getErrors | public Errors getErrors(String name)(Code) | | Retrieve the Errors instance for the given bind object,
using the "defaultHtmlEscape" setting.
Parameters: name - name of the bind object the Errors instance, or null if not found |
getErrors | public Errors getErrors(String name, boolean htmlEscape)(Code) | | Retrieve the Errors instance for the given bind object.
Parameters: name - name of the bind object Parameters: htmlEscape - create an Errors instance with automatic HTML escaping? the Errors instance, or null if not found |
getFallbackLocale | protected Locale getFallbackLocale()(Code) | | 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() .
the fallback locale (never null ) See Also: javax.servlet.http.HttpServletRequest.getLocale |
getFallbackTheme | protected Theme getFallbackTheme()(Code) | | Determine the fallback theme for this context.
The default implementation returns the default theme (with name "theme").
the fallback theme, or null |
getLocale | final public Locale getLocale()(Code) | | Return the current locale.
|
getMessage | public String getMessage(String code, String defaultMessage)(Code) | | Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
Parameters: code - code of the message Parameters: defaultMessage - String to return if the lookup fails the message |
getMessage | public String getMessage(String code, Object[] args, String defaultMessage)(Code) | | Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
Parameters: code - code of the message Parameters: args - arguments for the message, or null if none Parameters: defaultMessage - String to return if the lookup fails the message |
getMessage | public String getMessage(String code, List args, String defaultMessage)(Code) | | Retrieve the message for the given code, using the "defaultHtmlEscape" setting.
Parameters: code - code of the message Parameters: args - arguments for the message as a List, or null if none Parameters: defaultMessage - String to return if the lookup fails the message |
getMessage | public String getMessage(String code, Object[] args, String defaultMessage, boolean htmlEscape)(Code) | | Retrieve the message for the given code.
Parameters: code - code of the message Parameters: args - arguments for the message, or null if none Parameters: defaultMessage - String to return if the lookup fails Parameters: htmlEscape - HTML escape the message? the message |
getModelObject | protected Object getModelObject(String modelName)(Code) | | Retrieve the model object for the given model name,
either from the model or from the request attributes.
Parameters: modelName - the name of the model object the model object |
getRequest | final protected HttpServletRequest getRequest()(Code) | | Return the underlying HttpServletRequest.
Only intended for cooperating classes in this package.
|
getServletContext | final protected ServletContext getServletContext()(Code) | | Return the underlying ServletContext.
Only intended for cooperating classes in this package.
|
getTheme | final public Theme getTheme()(Code) | | Return the current theme.
|
getThemeMessage | public String getThemeMessage(String code, String defaultMessage)(Code) | | 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.
Parameters: code - code of the message Parameters: defaultMessage - String to return if the lookup fails the message |
getThemeMessage | public String getThemeMessage(String code, Object[] args, String defaultMessage)(Code) | | 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.
Parameters: code - code of the message Parameters: args - arguments for the message, or null if none Parameters: defaultMessage - String to return if the lookup fails the message |
getThemeMessage | public String getThemeMessage(String code, List args, String defaultMessage)(Code) | | 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.
Parameters: code - code of the message Parameters: args - arguments for the message as a List, or null if none Parameters: defaultMessage - String to return if the lookup fails the message |
getThemeMessage | public String getThemeMessage(String code, List args) throws NoSuchMessageException(Code) | | 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.
Parameters: code - code of the message Parameters: args - arguments for the message as a List, or null if none the message throws: org.springframework.context.NoSuchMessageException - if not found |
getUrlPathHelper | public UrlPathHelper getUrlPathHelper()(Code) | | 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.
|
isDefaultHtmlEscape | public boolean isDefaultHtmlEscape()(Code) | | Is default HTML escaping active?
|
setDefaultHtmlEscape | public void setDefaultHtmlEscape(boolean defaultHtmlEscape)(Code) | | (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).
See Also: org.springframework.web.util.WebUtils.isDefaultHtmlEscape |
setUrlPathHelper | public void setUrlPathHelper(UrlPathHelper urlPathHelper)(Code) | | 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.
|
|
|