|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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. |
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. |
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. |
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) throws javax.servlet.ServletException
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) throws javax.servlet.ServletException
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 |
public java.lang.String getContextPath()
HttpServletRequest.getContextPath()
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 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 |