Java Reference
In-Depth Information
Writing the Action Bean
The action bean provides the date to be displayed and changes it when
the user clicks one of the links. Action beans, action beans, all this
talk about action beans, but what exactly is an action bean, in terms
of code? It's a Java class that implements the ActionBean interface:
public interface ActionBean {
public void setContext(ActionBeanContext context);
public ActionBeanContext getContext();
}
This is just a getter and a setter method for the ActionBeanContext ,
which contains the current request and response objects along with
other useful information about the current request. Stripes takes care
of providing the ActionBeanContext to action beans, so you can always
count on having easy access to this information in your action beans
by calling getContext ( ).
Often, within an application, you'll write an abstract base class that
implements the ActionBean interface and have your concrete action
beans extend this base class. This also gives you a single place for
adding any code that you want to make available to all your action
beans.
There is only one action bean in this simple example, so we won't bother
creating a separate abstract base class. Let's look at the code for Hel-
loActionBean :
Download getting_started/src/stripesbook/action/HelloActionBean.java
package stripesbook.action;
import java.util.Date;
import java.util.Random;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
Ê
public class HelloActionBean implements ActionBean {
private ActionBeanContext ctx;
public ActionBeanContext getContext() { return ctx; }
public void setContext(ActionBeanContext ctx) { this .ctx = ctx; }
Ë
private Date date;
public Date getDate() {
return date;
}
 
 
Search WWH ::




Custom Search