View Javadoc

1   /*
2    * $Id: MappingDispatchExampleAction.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.MappingDispatchAction;
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  import org.apache.struts.action.ActionMessage;
27  import org.apache.struts.action.ActionMessages;
28  
29  /***
30   * Example DispatchAction.
31   *
32   * @version $Rev: 421488 $ $Date: 2006-07-12 20:43:08 -0700 (Wed, 12 Jul 2006) $
33   */
34  public class MappingDispatchExampleAction extends MappingDispatchAction {
35  
36      private int fooCount;
37      private int barCount;
38  
39      /***
40       * Example "foo" method.
41       *
42       * @param mapping The ActionMapping used to select this instance
43       * @param form The optional ActionForm bean for this request
44       * @param request The servlet request we are processing
45       * @param response The servlet response we are creating
46       *
47       * @exception Exception if business logic throws an exception
48       */
49      public ActionForward doFoo(ActionMapping mapping,
50                                 ActionForm form,
51                                 HttpServletRequest request,
52                                 HttpServletResponse response)
53          throws Exception {
54  
55          fooCount++;
56  
57          ActionMessages messages = new ActionMessages();
58          messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
59          saveMessages(request, messages);
60  
61          return (mapping.findForward("success"));
62  
63      }
64  
65      /***
66       * Example "bar" method.
67       *
68       * @param mapping The ActionMapping used to select this instance
69       * @param form The optional ActionForm bean for this request
70       * @param request The servlet request we are processing
71       * @param response The servlet response we are creating
72       *
73       * @exception Exception if business logic throws an exception
74       */
75      public ActionForward doBar(ActionMapping mapping,
76                                 ActionForm form,
77                                 HttpServletRequest request,
78                                 HttpServletResponse response)
79          throws Exception {
80          barCount++;
81  
82          ActionMessages messages = new ActionMessages();
83          messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
84          saveMessages(request, messages);
85  
86          return (mapping.findForward("success"));
87  
88      }
89  
90  }