KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > struts > action > FormViewDispatchAction


1 package net.sourceforge.formview.struts.action;
2
3 import javax.servlet.ServletContext JavaDoc;
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5 import javax.servlet.http.HttpServletResponse JavaDoc;
6 import net.sourceforge.formview.FormViewConstants;
7 import net.sourceforge.formview.util.WEBFormViewUtil;
8
9 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionForward;
11 import org.apache.struts.action.ActionMapping;
12 import org.apache.struts.actions.DispatchAction;
13
14 /**
15  * Description : Manage FormView and state into action forward.
16  *
17  * @author <a HREF="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
18  *
19  */

20 public abstract class FormViewDispatchAction extends DispatchAction {
21
22     
23     /**
24      * Save FormView into request with name of form (path of mapping)
25      * @param mapping
26      * @param actionForm
27      * @param request
28      * @param response
29      * @param name
30      * @return
31      * @throws Exception
32      */

33     protected ActionForward dispatchMethod(ActionMapping mapping,
34             ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, String JavaDoc name)
35             throws Exception JavaDoc {
36         ActionForward actionForward = super.dispatchMethod(mapping, form, request, response, name);
37         // Save formview into request
38
// with formName (=path)
39
ServletContext JavaDoc context = getServlet().getServletContext();
40         WEBFormViewUtil.saveFormView(request, context, mapping.getPath());
41         if (WEBFormViewUtil.isMergeFormViewWithStrutsActionErrors(request))
42             // Merge with struts action errors
43
WEBFormViewUtil.mergeFormViewWithStrutsActionErrors(request, context);
44         return actionForward;
45     }
46     
47     /**
48      * Reload action : call dispatch display.
49      * You can override this dispatch if you want to do another.
50      * @param mapping
51      * @param actionForm
52      * @param request
53      * @param response
54      * @return
55      * @throws Exception
56      */

57     public ActionForward reload(ActionMapping mapping, ActionForm actionForm,
58             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
59             throws Exception JavaDoc {
60         return display(mapping, actionForm, request, response);
61     }
62     
63     /**
64      * Dispatch Display To Implement
65      * (ex : load Business Object list...)
66      * @param mapping
67      * @param actionForm
68      * @param request
69      * @param response
70      * @return
71      * @throws Exception
72      */

73     public abstract ActionForward display(ActionMapping mapping,
74             ActionForm actionForm, HttpServletRequest JavaDoc request,
75             HttpServletResponse JavaDoc response) throws Exception JavaDoc;
76     
77     /**
78      * Load Create dispatch action : Set state to CREATE
79      * and call load dispatch Action.
80      * @param mapping
81      * @param form
82      * @param request
83      * @param response
84      * @param dispatchName
85      * @return
86      * @throws Exception
87      */

88     public final ActionForward loadCreate(ActionMapping mapping, ActionForm form,
89             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
90             throws Exception JavaDoc {
91         // Set state to CREATE
92
WEBFormViewUtil.saveState(request, getServlet().getServletContext(), FormViewConstants.STATE_CREATE);
93         return load(mapping, form, request, response);
94     }
95
96     /**
97      * Load Create dispatch action : Set state to READ
98      * and call load dispatch Action.
99      * @param mapping
100      * @param form
101      * @param request
102      * @param response
103      * @param dispatchName
104      * @return
105      * @throws Exception
106      */

107     public final ActionForward loadRead(ActionMapping mapping, ActionForm form,
108             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
109             throws Exception JavaDoc {
110         // Set state to READ
111
WEBFormViewUtil.saveState(request, getServlet().getServletContext(), FormViewConstants.STATE_READ);
112         return load(mapping, form, request, response);
113     }
114
115     /**
116      * Load Create dispatch action : Set state to UPDATE
117      * and call load dispatch Action.
118      * @param mapping
119      * @param form
120      * @param request
121      * @param response
122      * @param dispatchName
123      * @return
124      * @throws Exception
125      */

126     public final ActionForward loadUpdate(ActionMapping mapping, ActionForm form,
127             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
128             throws Exception JavaDoc {
129         // Set state to UPDATE
130
WEBFormViewUtil.saveState(request, getServlet().getServletContext(), FormViewConstants.STATE_UPDATE);
131         return load(mapping, form, request, response);
132     }
133     
134     public abstract ActionForward load(ActionMapping mapping,
135             ActionForm actionForm, HttpServletRequest JavaDoc request,
136             HttpServletResponse JavaDoc response) throws Exception JavaDoc;
137 }
138
Popular Tags