EventDispatchActionExample xref

View Javadoc

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