View Javadoc

1   /*
2    * $Id: EventActionDispatcherExample.java 421488 2006-07-13 03:43:08Z wsmoak $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.webapp.dispatch;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  import org.apache.struts.actions.ActionDispatcher;
23  import org.apache.struts.actions.EventActionDispatcher;
24  import org.apache.struts.action.Action;
25  import org.apache.struts.action.ActionForm;
26  import org.apache.struts.action.ActionForward;
27  import org.apache.struts.action.ActionMapping;
28  import org.apache.struts.action.ActionMessage;
29  import org.apache.struts.action.ActionMessages;
30  
31  /***
32   * Example EventActionDispatcher.
33   *
34   * @version $Rev: 421488 $ $Date: 2006-07-12 20:43:08 -0700 (Wed, 12 Jul 2006) $
35   */
36  public class EventActionDispatcherExample extends Action {
37  
38      private ActionDispatcher dispatcher
39                                   = new EventActionDispatcher(this);
40  
41      private int fooCount;
42      private int barCount;
43  
44      /***
45       * Execute method.
46       *
47       * @param mapping The ActionMapping used to select this instance
48       * @param form The optional ActionForm bean for this request
49       * @param request The servlet request we are processing
50       * @param response The servlet response we are creating
51       *
52       * @exception Exception if business logic throws an exception
53       */
54      public ActionForward execute(ActionMapping mapping,
55                                   ActionForm form,
56                                   HttpServletRequest request,
57                                   HttpServletResponse response)
58          throws Exception {
59  
60          return dispatcher.execute(mapping, form, request, response);
61  
62      }
63  
64      /***
65       * Example "foo" method.
66       *
67       * @param mapping The ActionMapping used to select this instance
68       * @param form The optional ActionForm bean for this request
69       * @param request The servlet request we are processing
70       * @param response The servlet response we are creating
71       *
72       * @exception Exception if business logic throws an exception
73       */
74      public ActionForward doFoo(ActionMapping mapping,
75                                 ActionForm form,
76                                 HttpServletRequest request,
77                                 HttpServletResponse response)
78          throws Exception {
79  
80          fooCount++;
81  
82          ActionMessages messages = new ActionMessages();
83          messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
84          saveMessages(request, messages);
85  
86          return (mapping.findForward("success"));
87  
88      }
89  
90      /***
91       * Example "bar" method.
92       *
93       * @param mapping The ActionMapping used to select this instance
94       * @param form The optional ActionForm bean for this request
95       * @param request The servlet request we are processing
96       * @param response The servlet response we are creating
97       *
98       * @exception Exception if business logic throws an exception
99       */
100     public ActionForward doBar(ActionMapping mapping,
101                                ActionForm form,
102                                HttpServletRequest request,
103                                HttpServletResponse response)
104         throws Exception {
105         barCount++;
106 
107         ActionMessages messages = new ActionMessages();
108         messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
109         saveMessages(request, messages);
110 
111         return (mapping.findForward("success"));
112 
113     }
114 
115 }