net.sourceforge.stripes.action
Interface ActionBean

All Known Implementing Classes:
DefaultViewActionBean

public interface ActionBean

Interface for all classes that respond to user interface events. Implementations receive information about the event (usually a form submission) in two ways. The first is through a ActionBeanContext object which will always be set on the ActionBean prior to any user implemented "handler" methods being invoked. The second is through the setting of JavaBean style properties on the object (and nested JavaBeans). Values submitted in an HTML Form will be bound to a property on the object if such a property is defined. The ActionBeanContext is used primarily to provide access to Servlet APIs such as the request and response, and other information generated during the pre-processing of the request.

How Stripes determines which method to invoke is based on Annotations as opposed to a strict interface. Firstly, each ActionBean should be annotated with a UrlBinding which specifies the path within the web application that the ActionBean will be bound to. E.g:

 @UrlBinding("/action/SampleAction")
 public SampleActionBean implements ActionBean {
 ...
 

At run time Stripes will discover all implementations of ActionBean and, when a form is submitted, will locate the ActionBean to use by matching the path in the request to the UrlBinding annotation on the ActionBean.

The way in which a specific event is mapped to a "handler" method can vary. The default method used by Stripes is to identify the name of the button or image button used to submit the request, and to find the handler method that can handle that event. The way this is declared in the ActionBean is like this:

 @HandlesEvent("SampleEvent")
 public Resolution sample() throws Exception {
     ...
     return new ForwardResolution("/SampleJsp2.jsp");
 }
 

Event names specified in the HandlesEvent annotation should be unique within a given ActionBean (and it's superclasses), but can be re-used across ActionBeans. For example, a given ActionBean should not have two methods with the annotation @HandlesEvent("Update"), but it would be perfectly reasonable to have two different ActionBeans handle events, from different forms, called Update.

It is also possible to designate a method as the default method for handling events in the case that Stripes cannot figure out a specific handler method to invoke. This occurs most often when a form is submitted by the user hitting the enter/return key, and so no form button is activated. Essentially the default handler is specifying the default operation for your form. In forms that have only one handler method, that method should always be declared as the default. For example:

 @HandlesEvent("Search")
 @DefaultHandler
 public Resolution findUsers() throws Exception {
     ...
     return new ForwardResolution("/SearchResults.jsp");
 }
 

Handler methods have two options for what to do when they have finished their processing. The preferred option is to return an instance of an implementation of Resolution. This keeps things clean and makes it a little easier to change how things work down the road. The other option is to return nothing, and simply use the Servlet API (available through the ActionBeanContext) to render a response to the user directly.

An ActionBean may optionally implement the ValidationErrorHandler interface which allows the ActionBean to modify what happens when validation errors occur.

Author:
Tim Fennell
See Also:
Resolution, ActionBeanContext, ValidationErrorHandler

Method Summary
 ActionBeanContext getContext()
          Implementations must implement this method to return a reference to the context object provided to the ActionBean during the call to setContext(ActionBeanContext).
 void setContext(ActionBeanContext context)
          Called by the Stripes dispatcher to provide context to the ActionBean before invoking the handler method.
 

Method Detail

setContext

void setContext(ActionBeanContext context)
Called by the Stripes dispatcher to provide context to the ActionBean before invoking the handler method. Implementations should store a reference to the context for use during event handling.

Parameters:
context - ActionBeanContext associated with the current request

getContext

ActionBeanContext getContext()
Implementations must implement this method to return a reference to the context object provided to the ActionBean during the call to setContext(ActionBeanContext).

Returns:
ActionBeanContext associated with the current request


? Copyright 2005-2006, Stripes Development Team.