net.sourceforge.stripes.action
Class ActionBeanContext

java.lang.Object
  extended by net.sourceforge.stripes.action.ActionBeanContext

public class ActionBeanContext
extends 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.

Author:
Tim Fennell

Constructor Summary
ActionBeanContext()
           
 
Method Summary
 String getEventName()
          Supplies the name of the event being handled.
 Locale getLocale()
          Gets the Locale that is being used to service the current request.
 List<Message> getMessages()
          Returns the default set of non-error messages associated with the current request.
 List<Message> getMessages(String key)
          Returns the set of non-error messages associated with the current request under the specified key.
 HttpServletRequest getRequest()
          Retrieves the HttpServletRequest object that is associated with the current request.
 HttpServletResponse getResponse()
          Retrieves the HttpServletResponse that is associated with the current request.
 ServletContext getServletContext()
          Retrieves the ServletContext object that is associated with the context in which the current request is being processed.
 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(String eventName)
          Used by the DispatcherServlet to set the name of the even being handled.
 void setRequest(HttpServletRequest request)
          Used by the DispatcherServlet to set the HttpServletRequest for the current request
 void setResponse(HttpServletResponse response)
          Used by the DispatcherServlet to set the HttpServletResponse that is associated with the current request.
 void setServletContext(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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActionBeanContext

public ActionBeanContext()
Method Detail

getRequest

public HttpServletRequest getRequest()
Retrieves the HttpServletRequest object that is associated with the current request.

Returns:
HttpServletRequest the current request

setRequest

public void setRequest(HttpServletRequest request)
Used by the DispatcherServlet to set the HttpServletRequest for the current request

Parameters:
request - the current request

getResponse

public HttpServletResponse getResponse()
Retrieves the HttpServletResponse that is associated with the current request.

Returns:
HttpServletResponse the current response

setResponse

public void setResponse(HttpServletResponse response)
Used by the DispatcherServlet to set the HttpServletResponse that is associated with the current request.

Parameters:
response - the current response

getServletContext

public ServletContext getServletContext()
Retrieves the ServletContext object that is associated with the context in which the current request is being processed.

Returns:
ServletContext the current ServletContext

setServletContext

public void setServletContext(ServletContext servletContext)
Sets the ServletContext object that is associated with the context in which the current request is being processed.

Parameters:
servletContext - the current ServletContext

getEventName

public String getEventName()
Supplies the name of the event being handled. While a specific method is usually invoked on an ActionBean, through the use of default handlers ambiguity can arise. This allows ActionBeans to definitively know the name of the event that was fired.

Returns:
String the name of the event being handled

setEventName

public void setEventName(String eventName)
Used by the DispatcherServlet to set the name of the even being handled.

Parameters:
eventName - the name of the event being handled

getValidationErrors

public ValidationErrors getValidationErrors()
Returns the set of validation errors associated with the current form. Lazily initialized the set of errors, and will never return null.

Returns:
a Collection of validation errors

setValidationErrors

public void setValidationErrors(ValidationErrors validationErrors)
Replaces the current set of validation errors.

Parameters:
validationErrors - a collect of validation errors

getMessages

public 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.

Returns:
a List of Message objects associated with the current request, never null.
See Also:
getMessages(String)

getMessages

public List<Message> getMessages(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.

Returns:
a List of Message objects associated with the current request, never null.

getLocale

public Locale getLocale()
Gets the Locale that is being used to service the current request. This is *not* the value that was submitted in the request, but the value picked by the configured LocalePicker which takes into consideration the locales preferred in the request.

Returns:
Locale the locale being used for the current request
See Also:
LocalePicker

getSourcePageResolution

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.

Returns:
Resolution a resolution that will forward the user to the page they came from
Throws:
IllegalStateException - if the information required to construct a source page resolution cannot be found in the request.
See Also:
getSourcePage()

getSourcePage

public String getSourcePage()

Returns the context-relative path to the page from which the user submitted they current request.

Returns:
Resolution a resolution that will forward the user to the page they came from
Throws:
IllegalStateException - if the information required to construct a source page resolution cannot be found in the request.
See Also:
getSourcePageResolution()

toString

public 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.

Overrides:
toString in class Object


? Copyright 2005-2006, Stripes Development Team.