Class RequestContext
java.lang.Object
org.springframework.web.reactive.result.view.RequestContext
Context holder for request-specific state, like the 
MessageSource to
 use, current locale, binding errors, etc. Provides easy access to localized
 messages and Errors instances.
 Suitable for exposition to views, and usage within FreeMarker templates and tag libraries.
Can be instantiated manually or automatically exposed to views as a model attribute via AbstractView's "requestContextAttribute" property.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev
- 
Constructor SummaryConstructorsConstructorDescriptionRequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource) RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource, RequestDataValueProcessor dataValueProcessor) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidchangeLocale(Locale locale) Change the current locale to the specified one.voidchangeLocale(Locale locale, TimeZone timeZone) Change the current locale to the specified locale and time zone context.getBindStatus(String path) Create a BindStatus for the given bind object using the "defaultHtmlEscape" setting.getBindStatus(String path, boolean htmlEscape) Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting.Return the context path of the current web application.getContextUrl(String relativeUrl) Return a context-aware URl for the given relative URL.getContextUrl(String relativeUrl, Map<String, ?> params) Return a context-aware URl for the given relative URL with placeholders -- named keys with braces{}.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.protected final ServerWebExchangefinal LocaleReturn the current Locale.getMessage(String code) Retrieve the message for the given code, using the "defaultHtmlEscape" setting.getMessage(String code, Object[] args) Retrieve the message for the given code, using the "defaultHtmlEscape" setting.getMessage(String code, Object[] args, boolean htmlEscape) Retrieve the message for the given code.getMessage(String code, Object[] args, String defaultMessage) Retrieve the message for the given code, using the "defaultHtmlEscape" setting.getMessage(String code, Object[] args, String defaultMessage, boolean htmlEscape) Retrieve the message for the given code.getMessage(String code, String defaultMessage) Retrieve the message for the given code, using the "defaultHtmlEscape" setting.getMessage(String code, List<?> args) Retrieve the message for the given code, using the "defaultHtmlEscape" setting.getMessage(String code, List<?> args, String defaultMessage) Retrieve the message for the given code, using the "defaultHtmlEscape" setting.getMessage(MessageSourceResolvable resolvable) Retrieve the given MessageSourceResolvable (e.g.getMessage(MessageSourceResolvable resolvable, boolean htmlEscape) Retrieve the given MessageSourceResolvable (e.g.Return the MessageSource in use with this request.getModel()Return the model Map that this RequestContext encapsulates, if any.protected <T> TgetModelObject(String modelName) Retrieve the model object for the given model name, either from the model or from the request attributes.Return the query string of the current request.Return theRequestDataValueProcessorinstance to apply to in form tag libraries and to redirect URLs.Return the request path of the request.Return the current TimeZone.booleanIs default HTML escaping active? Falls back tofalsein case of no explicit default given.voidsetDefaultHtmlEscape(boolean defaultHtmlEscape) (De)activate default HTML escaping for messages and errors, for the scope of this RequestContext.
- 
Constructor Details- 
RequestContextpublic RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource) 
- 
RequestContextpublic RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource, @Nullable RequestDataValueProcessor dataValueProcessor) 
 
- 
- 
Method Details- 
getExchange
- 
getMessageSourceReturn the MessageSource in use with this request.
- 
getModelReturn the model Map that this RequestContext encapsulates, if any.- Returns:
- the populated model Map, or nullif none available
 
- 
getLocaleReturn the current Locale.
- 
getTimeZoneReturn the current TimeZone.
- 
changeLocaleChange the current locale to the specified one.
- 
changeLocaleChange the current locale to the specified locale and time zone context.
- 
setDefaultHtmlEscapepublic void setDefaultHtmlEscape(boolean defaultHtmlEscape) (De)activate default HTML escaping for messages and errors, for the scope of this RequestContext.TODO: currently no application-wide setting ... 
- 
isDefaultHtmlEscapepublic boolean isDefaultHtmlEscape()Is default HTML escaping active? Falls back tofalsein case of no explicit default given.
- 
getDefaultHtmlEscapeReturn the default HTML escape setting, differentiating between no default specified and an explicit value.- Returns:
- whether default HTML escaping is enabled (null = no explicit default)
 
- 
getRequestDataValueProcessorReturn theRequestDataValueProcessorinstance to apply to in form tag libraries and to redirect URLs.
- 
getContextPathReturn the context path of the current web application. This is useful for building links to other resources within the application.Delegates to ServerHttpRequest.getPath().
- 
getContextUrlReturn a context-aware URl for the given relative URL.- Parameters:
- relativeUrl- the relative URL part
- Returns:
- a URL that points back to the current web application with an absolute path also URL-encoded accordingly
 
- 
getContextUrlReturn a context-aware URl for the given relative URL with placeholders -- named keys with braces{}. For example, send in a relative URLfoo/{bar}?spam={spam}and a parameter map{bar=baz,spam=nuts}and the result will be[contextpath]/foo/baz?spam=nuts.- Parameters:
- relativeUrl- the relative URL part
- params- a map of parameters to insert as placeholders in the url
- Returns:
- a URL that points back to the current web application with an absolute path also URL-encoded accordingly
 
- 
getRequestPathReturn the request path of the request. This is useful as HTML form action target, also in combination with the original query string.
- 
getQueryStringReturn the query string of the current request. This is useful for building an HTML form action target in combination with the original request path.
- 
getMessageRetrieve the message for the given code, using the "defaultHtmlEscape" setting.- Parameters:
- code- the code of the message
- defaultMessage- the String to return if the lookup fails
- Returns:
- the message
 
- 
getMessageRetrieve the message for the given code, using the "defaultHtmlEscape" setting.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- defaultMessage- the String to return if the lookup fails
- Returns:
- the message
 
- 
getMessageRetrieve the message for the given code, using the "defaultHtmlEscape" setting.- Parameters:
- code- the code of the message
- args- arguments for the message as a List, or- nullif none
- defaultMessage- the String to return if the lookup fails
- Returns:
- the message
 
- 
getMessagepublic String getMessage(String code, @Nullable Object[] args, String defaultMessage, boolean htmlEscape) Retrieve the message for the given code.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- defaultMessage- the String to return if the lookup fails
- htmlEscape- if the message should be HTML-escaped
- Returns:
- the message
 
- 
getMessageRetrieve the message for the given code, using the "defaultHtmlEscape" setting.- Parameters:
- code- the code of the message
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessageRetrieve the message for the given code, using the "defaultHtmlEscape" setting.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessageRetrieve the message for the given code, using the "defaultHtmlEscape" setting.- Parameters:
- code- the code of the message
- args- arguments for the message as a List, or- nullif none
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessagepublic String getMessage(String code, @Nullable Object[] args, boolean htmlEscape) throws NoSuchMessageException Retrieve the message for the given code.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- htmlEscape- if the message should be HTML-escaped
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessageRetrieve the given MessageSourceResolvable (e.g. an ObjectError instance), using the "defaultHtmlEscape" setting.- Parameters:
- resolvable- the MessageSourceResolvable
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessagepublic String getMessage(MessageSourceResolvable resolvable, boolean htmlEscape) throws NoSuchMessageException Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance).- Parameters:
- resolvable- the MessageSourceResolvable
- htmlEscape- if the message should be HTML-escaped
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getErrorsRetrieve the Errors instance for the given bind object, using the "defaultHtmlEscape" setting.- Parameters:
- name- the name of the bind object
- Returns:
- the Errors instance, or nullif not found
 
- 
getErrorsRetrieve the Errors instance for the given bind object.- Parameters:
- name- the name of the bind object
- htmlEscape- create an Errors instance with automatic HTML escaping?
- Returns:
- the Errors instance, or nullif not found
 
- 
getModelObjectRetrieve 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
- Returns:
- the model object
 
- 
getBindStatusCreate a BindStatus for the given bind object using the "defaultHtmlEscape" setting.- Parameters:
- path- the bean and property path for which values and errors will be resolved (e.g. "person.age")
- Returns:
- the new BindStatus instance
- Throws:
- IllegalStateException- if no corresponding Errors object found
 
- 
getBindStatusCreate a BindStatus for the given bind object, using the "defaultHtmlEscape" setting.- Parameters:
- 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?
- Returns:
- the new BindStatus instance
- Throws:
- IllegalStateException- if no corresponding Errors object found
 
 
-