Java技術專區(qū)--Hilly

          http://blog.duyouyou.com
             :: 首頁 :: 新隨筆 :: 聯(lián)系 ::  :: 管理

          LookupDispatchAction使用示例

          Posted on 2006-07-20 18:01 duyouyou.com 閱讀(930) 評論(0)  編輯  收藏 所屬分類: web技術
          LookupDispatchAction

          public abstract class LookupDispatchAction
          extends DispatchAction

          An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. To configure the use of this action in your struts-config.xml file, create an entry like this:

             <action path="/test"
                     type="org.example.MyAction"
                     name="MyForm"
                    scope="request"
                    input="/test.jsp"
                parameter="method"/>
           

          which will use the value of the request parameter named "method" to locate the corresponding key in ApplicationResources. For example, you might have the following ApplicationResources.properties:

              button.add=Add Record
              button.delete=Delete Record
            

          And your JSP would have the following format for submit buttons:

             <html:form action="/test">
              <html:submit property="method">
                <bean:message key="button.add"/>
              </html:submit>
              <html:submit property="method">
                <bean:message key="button.delete"/>
              </html:submit>
            </html:form>
            

          Your subclass must implement both getKeyMethodMap and the methods defined in the map. An example of such implementations are:

            protected Map getKeyMethodMap() {
                Map map = new HashMap();
                map.put("button.add", "add");
                map.put("button.delete", "delete");
                return map;
            }
          
            public ActionForward add(ActionMapping mapping,
                    ActionForm form,
                    HttpServletRequest request,
                    HttpServletResponse response)
                    throws IOException, ServletException {
                // do add
                return mapping.findForward("success");
            }
          
            public ActionForward delete(ActionMapping mapping,
                    ActionForm form,
                    HttpServletRequest request,
                    HttpServletResponse response)
                    throws IOException, ServletException {
                // do delete
                return mapping.findForward("success");
            }
            

          Notes - If duplicate values exist for the keys returned by getKeys, only the first one found will be returned. If no corresponding key is found then an exception will be thrown. You can override the method unspecified to provide a custom handler. If the submit was cancelled (a html:cancel button was pressed), the custom handler cancelled will be used instead.

          ?

          Hold住
          主站蜘蛛池模板: 临清市| 梅河口市| 肥城市| 宝鸡市| 凭祥市| 聊城市| 鄂尔多斯市| 神木县| 耿马| 东丽区| 瑞安市| 揭西县| 衡阳县| 镇远县| 岳池县| 商城县| 诏安县| 鄂托克前旗| 邵阳县| 同江市| 宽城| 元阳县| 昌乐县| 广灵县| 云南省| 宿松县| 昌都县| 涞水县| 商城县| 罗平县| 蒙阴县| 兴文县| 顺义区| 嫩江县| 麻城市| 甘泉县| 昆明市| 会理县| 垫江县| 衡阳市| 政和县|