public class ActionBeanContext
extends java.lang.Object
Encapsulates information about the current request. Also provides access to the underlying Servlet API should you need to use it for any reason.
Developers should generally consider subclassing ActionBeanContext to provide a facade to contextual state for their application. Type safe getters and setter can be added to the subclass and used by the application, thus hiding where the information is actually stored. This approach is documented in more detail in the Stripes documentation on State Management.
Constructor and Description |
---|
ActionBeanContext() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getEventName()
Supplies the name of the event being handled.
|
java.util.Locale |
getLocale()
Gets the Locale that is being used to service the current request.
|
java.util.List<Message> |
getMessages()
Returns the default set of non-error messages associated with the current request.
|
java.util.List<Message> |
getMessages(java.lang.String key)
Returns the set of non-error messages associated with the current request under the
specified key.
|
javax.servlet.http.HttpServletRequest |
getRequest()
Retrieves the HttpServletRequest object that is associated with the current request.
|
javax.servlet.http.HttpServletResponse |
getResponse()
Retrieves the HttpServletResponse that is associated with the current request.
|
javax.servlet.ServletContext |
getServletContext()
Retrieves the ServletContext object that is associated with the context in which the
current request is being processed.
|
java.lang.String |
getSourcePage()
Returns the context-relative path to the page from which the user submitted they current
request.
|
Resolution |
getSourcePageResolution()
Returns a resolution that can be used to return the user to the page from which they
submitted they current request.
|
ValidationErrors |
getValidationErrors()
Returns the set of validation errors associated with the current form.
|
void |
setEventName(java.lang.String eventName)
Used by the DispatcherServlet to set the name of the even being handled.
|
void |
setRequest(javax.servlet.http.HttpServletRequest request)
Used by the DispatcherServlet to set the HttpServletRequest for the current request
|
void |
setResponse(javax.servlet.http.HttpServletResponse response)
Used by the DispatcherServlet to set the HttpServletResponse that is associated with
the current request.
|
void |
setServletContext(javax.servlet.ServletContext servletContext)
Sets the ServletContext object that is associated with the context in which the
current request is being processed.
|
void |
setValidationErrors(ValidationErrors validationErrors)
Replaces the current set of validation errors.
|
java.lang.String |
toString()
Returns a String with the name of the event for which the instance holds context, and
the set of validation errors, if any.
|
public javax.servlet.http.HttpServletRequest getRequest()
public void setRequest(javax.servlet.http.HttpServletRequest request)
request
- the current requestpublic javax.servlet.http.HttpServletResponse getResponse()
public void setResponse(javax.servlet.http.HttpServletResponse response)
response
- the current responsepublic javax.servlet.ServletContext getServletContext()
public void setServletContext(javax.servlet.ServletContext servletContext)
servletContext
- the current ServletContextpublic java.lang.String getEventName()
public void setEventName(java.lang.String eventName)
eventName
- the name of the event being handledpublic ValidationErrors getValidationErrors()
public void setValidationErrors(ValidationErrors validationErrors)
validationErrors
- a collect of validation errorspublic java.util.List<Message> getMessages()
Returns the default set of non-error messages associated with the current request. Guaranteed to always return a List, though the list may be empty. It is envisaged that messages will normally be added to the request as follows:
getContext().getMessages().add( ... );
To remove messages from the current request fetch the list of messages and invoke remove() or clear(). Messages will be made available to JSPs during the current request and in the subsequent request if a redirect is issued.
getMessages(String)
public java.util.List<Message> getMessages(java.lang.String key)
Returns the set of non-error messages associated with the current request under the specified key. Can be used to manage multiple lists of messages, for different purposes. Guaranteed to always return a List, though the list may be empty. It is envisaged that messages will normally be added to the request as follows:
getContext().getMessages(key).add( ... );
To remove messages from the current request fetch the list of messages and invoke remove() or clear().
Messages are stored in a FlashScope
for
the current request. This means that they are available in request scope using the
supplied key during both this request, and the subsequent request if it is the result
of a redirect.
public java.util.Locale getLocale()
LocalePicker
public Resolution getSourcePageResolution()
Returns a resolution that can be used to return the user to the page from which they submitted they current request. Most useful in situations where a user-correctable error has occurred that was too difficult or expensive to check at validation time. In that case an ActionBean can call setValidationErrors() and then return the resolution provided by this method.
java.lang.IllegalStateException
- if the information required to construct a source page
resolution cannot be found in the request.getSourcePage()
public java.lang.String getSourcePage()
Returns the context-relative path to the page from which the user submitted they current request.
java.lang.IllegalStateException
- if the information required to construct a source page
resolution cannot be found in the request.getSourcePageResolution()
public java.lang.String toString()
toString
in class java.lang.Object
? Copyright 2005-2006, Stripes Development Team.