|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.web.servlet.support.RequestContext
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.
AbstractView.setRequestContextAttribute(java.lang.String)
,
UrlBasedViewResolver.setRequestContextAttribute(java.lang.String)
Constructor Summary | |
RequestContext(javax.servlet.http.HttpServletRequest request)
Create a new RequestContext for the given request, using the request attributes for Errors retrieval. |
|
RequestContext(javax.servlet.http.HttpServletRequest request,
java.util.Map model)
Create a new RequestContext for the given request, using the given model attributes for Errors retrieval. |
Method Summary | |
BindStatus |
getBindStatus(java.lang.String path)
Create a BindStatus for the given bind object, using the defaultHtmlEscape setting. |
BindStatus |
getBindStatus(java.lang.String path,
boolean htmlEscape)
Create a BindStatus for the given bind object, using the defaultHtmlEscape setting. |
java.lang.String |
getContextPath()
Return the context path of the current request, i.e. the path that indicates the current web application. |
Errors |
getErrors(java.lang.String name)
Retrieve the Errors instance for the given bind object, using the defaultHtmlEscape setting. |
Errors |
getErrors(java.lang.String name,
boolean htmlEscape)
Retrieve the Errors instance for the given bind object. |
java.util.Locale |
getLocale()
Return the current locale. |
java.lang.String |
getMessage(MessageSourceResolvable resolvable)
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance), using the defaultHtmlEscape setting. |
java.lang.String |
getMessage(MessageSourceResolvable resolvable,
boolean htmlEscape)
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance). |
java.lang.String |
getMessage(java.lang.String code)
Retrieve the message for the given code, using the defaultHtmlEscape setting. |
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args)
Retrieve the message for the given code, using the defaultHtmlEscape setting. |
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args,
boolean htmlEscape)
Retrieve the message for the given code. |
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args,
java.lang.String defaultMessage)
Retrieve the message for the given code, using the defaultHtmlEscape setting. |
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args,
java.lang.String defaultMessage,
boolean htmlEscape)
Retrieve the message for the given code. |
java.lang.String |
getMessage(java.lang.String code,
java.lang.String defaultMessage)
Retrieve the message for the given code, using the defaultHtmlEscape setting. |
protected javax.servlet.http.HttpServletRequest |
getRequest()
Return the underlying HttpServletRequest. |
java.lang.String |
getRequestUri()
Return the request URI of the current request, i.e. the invoked URL without parameters. |
Theme |
getTheme()
Return the current theme. |
java.lang.String |
getThemeMessage(MessageSourceResolvable resolvable)
Retrieve the given MessageSourceResolvable in the current theme. |
java.lang.String |
getThemeMessage(java.lang.String code)
Retrieve the theme message for the given code. |
java.lang.String |
getThemeMessage(java.lang.String code,
java.lang.String defaultMessage)
Retrieve the theme message for the given code. |
java.lang.String |
getThemeMessage(java.lang.String code,
java.lang.String[] args)
Retrieve the theme message for the given code. |
java.lang.String |
getThemeMessage(java.lang.String code,
java.lang.String[] args,
java.lang.String defaultMessage)
Retrieve the theme message for the given code. |
UrlPathHelper |
getUrlPathHelper()
Return the UrlPathHelper used for context path and request URI decoding. |
WebApplicationContext |
getWebApplicationContext()
Return the current WebApplicationContext. |
boolean |
isDefaultHtmlEscape()
Is default HTML escaping active? |
void |
setDefaultHtmlEscape(boolean defaultHtmlEscape)
(De)activate default HTML escaping for messages and errors, for the scope of this RequestContext. |
void |
setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for context path and request URI decoding. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RequestContext(javax.servlet.http.HttpServletRequest request)
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.
request
- current HTTP requestpublic RequestContext(javax.servlet.http.HttpServletRequest request, java.util.Map model)
This works with all View implementations. It will typically be used by View implementations.
request
- current HTTP requestmodel
- the model attributes for the current viewMethod Detail |
protected javax.servlet.http.HttpServletRequest getRequest()
public WebApplicationContext getWebApplicationContext()
public java.util.Locale getLocale()
public Theme getTheme()
public void setDefaultHtmlEscape(boolean defaultHtmlEscape)
WebUtils.isDefaultHtmlEscape(javax.servlet.ServletContext)
public boolean isDefaultHtmlEscape()
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
A default UrlPathHelper is always available.
public UrlPathHelper getUrlPathHelper()
A default UrlPathHelper is always available.
public java.lang.String getContextPath()
Delegates to the UrlPathHelper for decoding.
HttpServletRequest.getContextPath()
,
getUrlPathHelper()
public java.lang.String getRequestUri()
Note that you should create your RequestContext instance before forwarding to your JSP view, if you intend to determine the request URI! The optimal way to do so is to set "requestContextAttribute" on your view. Else, you'll get the URI of your JSP rather than the one of your controller.
Side note: As alternative for an HTML form action, either specify an empty "action" or omit the "action" attribute completely. This is not covered by the HTML spec, though, but known to work reliably on all current browsers.
Delegates to the UrlPathHelper for decoding.
HttpServletRequest.getRequestURI()
,
getUrlPathHelper()
,
AbstractView.setRequestContextAttribute(java.lang.String)
,
UrlBasedViewResolver.setRequestContextAttribute(java.lang.String)
public java.lang.String getMessage(java.lang.String code, java.lang.String defaultMessage)
code
- code of the messagedefaultMessage
- String to return if the lookup fails
public java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.lang.String defaultMessage)
code
- code of the messageargs
- arguments for the message, or null if nonedefaultMessage
- String to return if the lookup fails
public java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.lang.String defaultMessage, boolean htmlEscape)
code
- code of the messageargs
- arguments for the message, or null if nonedefaultMessage
- String to return if the lookup failshtmlEscape
- HTML escape the message?
public java.lang.String getMessage(java.lang.String code) throws NoSuchMessageException
code
- code of the message
NoSuchMessageException
- if not foundpublic java.lang.String getMessage(java.lang.String code, java.lang.Object[] args) throws NoSuchMessageException
code
- code of the messageargs
- arguments for the message, or null if none
NoSuchMessageException
- if not foundpublic java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, boolean htmlEscape) throws NoSuchMessageException
code
- code of the messageargs
- arguments for the message, or null if nonehtmlEscape
- HTML escape the message?
NoSuchMessageException
- if not foundpublic java.lang.String getMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException
resolvable
- the MessageSourceResolvable
NoSuchMessageException
- if not foundpublic java.lang.String getMessage(MessageSourceResolvable resolvable, boolean htmlEscape) throws NoSuchMessageException
resolvable
- the MessageSourceResolvablehtmlEscape
- HTML escape the message?
NoSuchMessageException
- if not foundpublic java.lang.String getThemeMessage(java.lang.String code, java.lang.String defaultMessage)
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 messagedefaultMessage
- String to return if the lookup fails
public java.lang.String getThemeMessage(java.lang.String code, java.lang.String[] args, java.lang.String defaultMessage)
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 messageargs
- arguments for the message, or null if nonedefaultMessage
- String to return if the lookup fails
public java.lang.String getThemeMessage(java.lang.String code) throws NoSuchMessageException
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 foundpublic java.lang.String getThemeMessage(java.lang.String code, java.lang.String[] args) throws NoSuchMessageException
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 messageargs
- arguments for the message, or null if none
NoSuchMessageException
- if not foundpublic java.lang.String getThemeMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException
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 foundpublic Errors getErrors(java.lang.String name)
name
- name of the bind object
public Errors getErrors(java.lang.String name, boolean htmlEscape)
name
- name of the bind objecthtmlEscape
- create an Errors instance with automatic HTML escaping?
public BindStatus getBindStatus(java.lang.String path) throws java.lang.IllegalStateException
path
- the bean and property path for which values and errors
will be resolved (e.g. "person.age")
java.lang.IllegalStateException
- if no corresponding Errors object foundpublic BindStatus getBindStatus(java.lang.String path, boolean htmlEscape) throws java.lang.IllegalStateException
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?
java.lang.IllegalStateException
- if no corresponding Errors object found
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |