Use lookupdispatchaction to implement multiple submit of a form

Source: Internet
Author: User
Tags deprecated
Document directory
  • Localemap
  • Keymethodmap
  • Lookupdispatchaction
  • Execute
  • Initlookupmap
  • Getkeymethodmap
  • Getlookupmapname
  • Getmethodname
 

Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
 Prev classNext class FramesNo Frames
All classes
All classes

Summary: Nested | FIELD | constr | Method Detail: field | constr | Method


Org. Apache. Struts. Actions
Class lookupdispatchaction
java.lang.Object  org.apache.struts.action.Action      org.apache.struts.actions.DispatchAction          org.apache.struts.actions.LookupDispatchAction
Public abstract class Lookupdispatchaction

Extends dispatchaction

An abstractActionThat dispatches to the subclass mappedexecuteMethod. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified byparameterProperty of the corresponding actionmapping. to configure the use of this action in yourstruts-config.xmlFile, 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 wocould have the following format for submit buttons:

   

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.

Field Summary
protected  java.util.Map keyMethodMap
Resource Key to Method Name Lookup.
protected  java.util.Map localeMap
Reverse lookup map from resource value to Resource Key.

 

Fields inherited from class org. Apache. Struts. Actions. dispatchaction
clazz, log, messages, methods, types

 

Fields inherited from class org. Apache. Struts. action. Action
defaultLocale, servlet

 

Constructor Summary
LookupDispatchAction()

 

Method Summary
 ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Process the specified HTTP request, and create the corresponding HTTP Response (or forward to another Web component that will create it ).
protected abstract  java.util.Map getKeyMethodMap()
Provides the mapping from Resource Key to method name.
protected  java.lang.String getLookupMapName(javax.servlet.http.HttpServletRequest request, java.lang.String keyName, ActionMapping mapping)
Lookup the method name corresponding to the client request's locale.
protected  java.lang.String getMethodName(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String parameter)
Returns the method name, given a parameter's value.
private  java.util.Map initLookupMap(javax.servlet.http.HttpServletRequest request, java.util.Locale userLocale)
This is the first time this locale is used so build the reverse lookup map.

 

Methods inherited from class org. Apache. Struts. Actions. dispatchaction
cancelled, dispatchMethod, getMethod, unspecified

 

Methods inherited from class org. Apache. Struts. action. Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet

 

Methods inherited from class java. Lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field detail


Localemap

protected java.util.Map localeMap
Reverse lookup map from resource value to Resource Key.


Keymethodmap
protected java.util.Map keyMethodMap
Resource Key to Method Name Lookup.

Constructor detail


Lookupdispatchaction

public LookupDispatchAction()

Method detail


Execute

public ActionForward execute(ActionMapping mapping,                             ActionForm form,                             javax.servlet.http.HttpServletRequest request,                             javax.servlet.http.HttpServletResponse response)                      throws java.lang.Exception
Process the specified HTTP request, and create the corresponding HTTP
Response (or forward to another Web component that will create it ).
Return ActionForwardInstance describing where and how
Control shocould be forwarded, or nullIf the response has
Already been completed.

Overrides:
executeIn Class DispatchAction
Parameters:
mapping-The actionmapping used to select this instance
request-The HTTP request we are processing
response-The HTTP response we are creating
form-The optional actionform bean for this request (if any)
Returns:
Describes where and how control shocould be forwarded.
Throws:
java.lang.Exception-If an error occurs

Initlookupmap
private java.util.Map initLookupMap(javax.servlet.http.HttpServletRequest request,                                    java.util.Locale userLocale)
This is the first time this locale is used so build the reverse lookup map.
Search for message keys in all configured messageresources
The current module.


Getkeymethodmap
protected abstract java.util.Map getKeyMethodMap()
Provides the mapping from Resource Key to method name.

Returns:
Resource Key/method name map.

Getlookupmapname
protected java.lang.String getLookupMapName(javax.servlet.http.HttpServletRequest request,                                            java.lang.String keyName,                                            ActionMapping mapping)                                     throws javax.servlet.ServletException
Lookup the method name corresponding to the client request's locale.

Parameters:
request-The HTTP request we are processing
keyName-The parameter name to use as the properties key
mapping-The actionmapping used to select this instance
Returns:
The method's localized name.
Throws:
javax.servlet.ServletException-If keyname cannot be resolved
Since:
Struts 1.2.0

Getmethodname
protected java.lang.String getMethodName(ActionMapping mapping,                                         ActionForm form,                                         javax.servlet.http.HttpServletRequest request,                                         javax.servlet.http.HttpServletResponse response,                                         java.lang.String parameter)                                  throws java.lang.Exception
Returns the method name, given a parameter's value.

Overrides:
getMethodNameIn Class DispatchAction
Parameters:
mapping-The actionmapping used to select this instance
form-The optional actionform bean for this request (if any)
request-The HTTP request we are processing
response-The HTTP response we are creating
parameter- ActionMappingParameter's name
Returns:
The method's name.
Throws:
java.lang.Exception
Since:
Struts 1.2.0




Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
 Prev classNext class FramesNo FramesAll classes
All classes

Summary: Nested | FIELD | constr | Method Detail: field | constr | Method


Copyright 2000-2004-the Apache Software Foundation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.