com.interface21.web.servlet.support
Class RequestContext

java.lang.Object
  |
  +--com.interface21.web.servlet.support.RequestContext

public class RequestContext
extends java.lang.Object

Context holder for request-specific state, like current web application context, current locale, and possible binding errors. Suitable for exposition to views, and usage within , JSP scriptlets, JSTL EL, Velocity templates, etc. Especially well-suited for views that do not have access to the servlet request, like Velocity templates.

Since:
03.03.2003
Author:
Juergen Hoeller
See Also:
AbstractView

Constructor Summary
RequestContext(javax.servlet.http.HttpServletRequest request)
          Creates a new RequestContext for the given request, using the request attributes for Errors retrieval.
RequestContext(javax.servlet.http.HttpServletRequest request, java.util.Map model)
          Creates a new RequestContext for the given request, using the given model attributes for Errors retrieval.
 
Method Summary
 Errors getErrors(java.lang.String name)
          Retrieves the Errors instance for the given bind object, using the defaultHtmlEscape setting.
 Errors getErrors(java.lang.String name, boolean htmlEscape)
          Retrieves the Errors instance for the given bind object.
 java.util.Locale getLocale()
          Returns the current locale.
 java.lang.String getMessage(MessageSourceResolvable resolvable)
          Retrieves the given MessageSourceResolvable (e.g. an ObjectError instance), using the defaultHtmlEscape setting.
 java.lang.String getMessage(MessageSourceResolvable resolvable, boolean htmlEscape)
          Retrieves the given MessageSourceResolvable (e.g. an ObjectError instance).
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args)
          Retrieves the message for the given code, using the defaultHtmlEscape setting.
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, boolean htmlEscape)
          Retrieves the message for the given code.
 Theme getTheme()
          Returns the current theme.
 WebApplicationContext getWebApplicationContext()
          Returns the current WebApplicationContext.
 boolean isDefaultHtmlEscape()
          Default HTML escaping?
 void setDefaultHtmlEscape(boolean defaultHtmlEscape)
          (De)actives default HTML escaping for messages and errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestContext

public RequestContext(javax.servlet.http.HttpServletRequest request)
               throws javax.servlet.ServletException
Creates 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.

Parameters:
request - current HTTP request

RequestContext

public RequestContext(javax.servlet.http.HttpServletRequest request,
                      java.util.Map model)
               throws javax.servlet.ServletException
Creates 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.

Parameters:
request - current HTTP request
model - the model attributes for the current view
Method Detail

getWebApplicationContext

public WebApplicationContext getWebApplicationContext()
Returns the current WebApplicationContext.

setDefaultHtmlEscape

public void setDefaultHtmlEscape(boolean defaultHtmlEscape)
(De)actives default HTML escaping for messages and errors.

isDefaultHtmlEscape

public boolean isDefaultHtmlEscape()
Default HTML escaping?

getLocale

public java.util.Locale getLocale()
Returns the current locale.

getTheme

public Theme getTheme()
Returns the current theme.

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args)
                            throws NoSuchMessageException
Retrieves the message for the given code, using the defaultHtmlEscape setting.
Parameters:
code - code of the message
args - arguments for the message, or null if none
Returns:
the message

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args,
                                   boolean htmlEscape)
                            throws NoSuchMessageException
Retrieves the message for the given code.
Parameters:
code - code of the message
args - arguments for the message, or null if none
htmlEscape - HTML escape the message?
Returns:
the message

getMessage

public java.lang.String getMessage(MessageSourceResolvable resolvable)
                            throws NoSuchMessageException
Retrieves the given MessageSourceResolvable (e.g. an ObjectError instance), using the defaultHtmlEscape setting.
Parameters:
resolvable - the MessageSourceResolvable
Returns:
the message

getMessage

public java.lang.String getMessage(MessageSourceResolvable resolvable,
                                   boolean htmlEscape)
                            throws NoSuchMessageException
Retrieves the given MessageSourceResolvable (e.g. an ObjectError instance).
Parameters:
resolvable - the MessageSourceResolvable
htmlEscape - HTML escape the message?
Returns:
the message

getErrors

public Errors getErrors(java.lang.String name)
Retrieves the Errors instance for the given bind object, using the defaultHtmlEscape setting.
Parameters:
name - name of the bind object
Returns:
the Errors instance

getErrors

public Errors getErrors(java.lang.String name,
                        boolean htmlEscape)
Retrieves the Errors instance for the given bind object.
Parameters:
name - name of the bind object
htmlEscape - create an Errors instance with automatic HTML escaping?
Returns:
the Errors instance


Rod Johnson and Spring contributors 2001-2003.