001: /*
002: * $Id: ActionDispatcherExample.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.webapp.dispatch;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025: import org.apache.struts.actions.ActionDispatcher;
026: import org.apache.struts.action.Action;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionForward;
029: import org.apache.struts.action.ActionMapping;
030: import org.apache.struts.action.ActionMessage;
031: import org.apache.struts.action.ActionMessages;
032:
033: /**
034: * Example DispatchAction.
035: *
036: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
037: */
038: public class ActionDispatcherExample extends Action {
039:
040: private ActionDispatcher dispatcher = new ActionDispatcher(this ,
041: ActionDispatcher.DISPATCH_FLAVOR);
042:
043: private int fooCount;
044: private int barCount;
045:
046: /**
047: * Execute method.
048: *
049: * @param mapping The ActionMapping used to select this instance
050: * @param form The optional ActionForm bean for this request
051: * @param request The servlet request we are processing
052: * @param response The servlet response we are creating
053: *
054: * @exception Exception if business logic throws an exception
055: */
056: public ActionForward execute(ActionMapping mapping,
057: ActionForm form, HttpServletRequest request,
058: HttpServletResponse response) throws Exception {
059:
060: return dispatcher.execute(mapping, form, request, response);
061:
062: }
063:
064: /**
065: * Example "foo" method.
066: *
067: * @param mapping The ActionMapping used to select this instance
068: * @param form The optional ActionForm bean for this request
069: * @param request The servlet request we are processing
070: * @param response The servlet response we are creating
071: *
072: * @exception Exception if business logic throws an exception
073: */
074: public ActionForward doFoo(ActionMapping mapping, ActionForm form,
075: HttpServletRequest request, HttpServletResponse response)
076: throws Exception {
077:
078: fooCount++;
079:
080: ActionMessages messages = new ActionMessages();
081: messages.add("foo", new ActionMessage("count.foo.message",
082: fooCount + ""));
083: saveMessages(request, messages);
084:
085: return (mapping.findForward("success"));
086:
087: }
088:
089: /**
090: * Example "bar" method.
091: *
092: * @param mapping The ActionMapping used to select this instance
093: * @param form The optional ActionForm bean for this request
094: * @param request The servlet request we are processing
095: * @param response The servlet response we are creating
096: *
097: * @exception Exception if business logic throws an exception
098: */
099: public ActionForward doBar(ActionMapping mapping, ActionForm form,
100: HttpServletRequest request, HttpServletResponse response)
101: throws Exception {
102: barCount++;
103:
104: ActionMessages messages = new ActionMessages();
105: messages.add("bar", new ActionMessage("count.bar.message",
106: barCount + ""));
107: saveMessages(request, messages);
108:
109: return (mapping.findForward("success"));
110:
111: }
112:
113: }
|