001: /*
002: * $Id: EventActionDispatcherExample.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.actions.EventActionDispatcher;
027: import org.apache.struts.action.Action;
028: import org.apache.struts.action.ActionForm;
029: import org.apache.struts.action.ActionForward;
030: import org.apache.struts.action.ActionMapping;
031: import org.apache.struts.action.ActionMessage;
032: import org.apache.struts.action.ActionMessages;
033:
034: /**
035: * Example EventActionDispatcher.
036: *
037: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
038: */
039: public class EventActionDispatcherExample extends Action {
040:
041: private ActionDispatcher dispatcher = new EventActionDispatcher(
042: this );
043:
044: private int fooCount;
045: private int barCount;
046:
047: /**
048: * Execute method.
049: *
050: * @param mapping The ActionMapping used to select this instance
051: * @param form The optional ActionForm bean for this request
052: * @param request The servlet request we are processing
053: * @param response The servlet response we are creating
054: *
055: * @exception Exception if business logic throws an exception
056: */
057: public ActionForward execute(ActionMapping mapping,
058: ActionForm form, HttpServletRequest request,
059: HttpServletResponse response) throws Exception {
060:
061: return dispatcher.execute(mapping, form, request, response);
062:
063: }
064:
065: /**
066: * Example "foo" method.
067: *
068: * @param mapping The ActionMapping used to select this instance
069: * @param form The optional ActionForm bean for this request
070: * @param request The servlet request we are processing
071: * @param response The servlet response we are creating
072: *
073: * @exception Exception if business logic throws an exception
074: */
075: public ActionForward doFoo(ActionMapping mapping, ActionForm form,
076: HttpServletRequest request, HttpServletResponse response)
077: throws Exception {
078:
079: fooCount++;
080:
081: ActionMessages messages = new ActionMessages();
082: messages.add("foo", new ActionMessage("count.foo.message",
083: fooCount + ""));
084: saveMessages(request, messages);
085:
086: return (mapping.findForward("success"));
087:
088: }
089:
090: /**
091: * Example "bar" method.
092: *
093: * @param mapping The ActionMapping used to select this instance
094: * @param form The optional ActionForm bean for this request
095: * @param request The servlet request we are processing
096: * @param response The servlet response we are creating
097: *
098: * @exception Exception if business logic throws an exception
099: */
100: public ActionForward doBar(ActionMapping mapping, ActionForm form,
101: HttpServletRequest request, HttpServletResponse response)
102: throws Exception {
103: barCount++;
104:
105: ActionMessages messages = new ActionMessages();
106: messages.add("bar", new ActionMessage("count.bar.message",
107: barCount + ""));
108: saveMessages(request, messages);
109:
110: return (mapping.findForward("success"));
111:
112: }
113:
114: }
|