001: /*
002: * $Id: LookupDispatchExampleAction.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 java.util.Map;
024: import java.util.HashMap;
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027: import org.apache.struts.actions.LookupDispatchAction;
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 LookupDispatchAction.
036: *
037: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
038: */
039: public class LookupDispatchExampleAction extends LookupDispatchAction {
040:
041: private Map keyMethodMap = new HashMap();
042: private int fooCount;
043: private int barCount;
044:
045: /**
046: * Constructor - populate the key method map.
047: */
048: public LookupDispatchExampleAction() {
049: keyMethodMap.put("button.foo.label", "doFoo");
050: keyMethodMap.put("button.bar.label", "doBar");
051: }
052:
053: /**
054: * Example "foo" method.
055: *
056: * @param mapping The ActionMapping used to select this instance
057: * @param form The optional ActionForm bean for this request
058: * @param request The servlet request we are processing
059: * @param response The servlet response we are creating
060: *
061: * @exception Exception if business logic throws an exception
062: */
063: public ActionForward doFoo(ActionMapping mapping, ActionForm form,
064: HttpServletRequest request, HttpServletResponse response)
065: throws Exception {
066:
067: fooCount++;
068:
069: ActionMessages messages = new ActionMessages();
070: messages.add("foo", new ActionMessage("count.foo.message",
071: fooCount + ""));
072: saveMessages(request, messages);
073:
074: return (mapping.findForward("success"));
075:
076: }
077:
078: /**
079: * Example "bar" method.
080: *
081: * @param mapping The ActionMapping used to select this instance
082: * @param form The optional ActionForm bean for this request
083: * @param request The servlet request we are processing
084: * @param response The servlet response we are creating
085: *
086: * @exception Exception if business logic throws an exception
087: */
088: public ActionForward doBar(ActionMapping mapping, ActionForm form,
089: HttpServletRequest request, HttpServletResponse response)
090: throws Exception {
091: barCount++;
092:
093: ActionMessages messages = new ActionMessages();
094: messages.add("bar", new ActionMessage("count.bar.message",
095: barCount + ""));
096: saveMessages(request, messages);
097:
098: return (mapping.findForward("success"));
099:
100: }
101:
102: /**
103: * Provides the mapping from resource key to method name.
104: *
105: * @return Resource key / method name map.
106: */
107: protected Map getKeyMethodMap() {
108: return keyMethodMap;
109: }
110:
111: }
|