KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > ctl > ThrowawayFormBeanUser


1 /*
2  * $Id: ThrowawayFormBeanUser.java,v 1.4 2003/09/27 19:39:33 thusted Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/ctl/ThrowawayFormBeanUser.java,v $
4  */

5
6 package org.infohazard.maverick.ctl;
7
8 import org.apache.commons.beanutils.BeanUtils;
9
10 /**
11  * This is a hybrid between Throwaway and FormBeanUser - the controller
12  * is instantiated like a Throwaway, but allows a form bean to be
13  * populated instead.
14  */

15 public abstract class ThrowawayFormBeanUser extends Throwaway2
16 {
17     /**
18      * The form bean gets set here
19      */

20     private Object JavaDoc formBean;
21
22     /**
23      */

24     protected Object JavaDoc getForm()
25     {
26         return this.formBean;
27     }
28
29     /**
30      * Executes this controller. Override the perform()
31      * method to provide application logic.
32      */

33     public final String JavaDoc go() throws Exception JavaDoc
34     {
35         this.formBean = this.makeFormBean();
36
37         BeanUtils.populate(this.formBean, this.getCtx().getRequest().getParameterMap());
38         BeanUtils.populate(this.formBean, this.getCtx().getControllerParams());
39
40         this.getCtx().setModel(this.formBean);
41
42         return this.perform();
43     }
44
45     /**
46      * This method can be overriden to perform application logic.
47      *
48      * Override this method if you want the model to be something
49      * other than the formBean itself.
50      *
51      * Use getForm to retrieve the bean created by makeFormBean(),
52      * which has been populated with the http request parameters.
53      */

54     protected String JavaDoc perform() throws Exception JavaDoc
55     {
56         return SUCCESS;
57     }
58
59     /**
60      * This method will be called to produce a simple bean whose properties
61      * will be populated with the http request parameters. The parameters
62      * are useful for doing things like persisting beans across requests.
63      *
64      * Default is to return this.
65      */

66     protected Object JavaDoc makeFormBean()
67     {
68         return this;
69     }
70 }
Popular Tags