org.apache.struts.actions
クラス 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

サブクラスにてマッピングされた execute メソッドに対して処理を割り振る機能を持つ抽象 Action です。 これは HTML フォームが同名で複数のサブミットボタンを持っている場合に有用です。 ボタンの名称は対応する ActionMapping の parameter プロパティにて指定されます。 このアクションを使用する場合には、以下のようなエントリを struts-config.xml ファイルに記述します:

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"/>
 

このエントリでは "action" という名前のリクエストパラメータの値を該当する ApplicationResources のキーを検索する際に使用します。 例えば以下のような ApplicationResources.properties を用意します:

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
  

また、JSPには以下のようなフォーマットのサブミットボタンを用意します:

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>
  

サブクラスでは getKeyMethodMap メソッドとマップ内に定義した名前を持つメソッドを定義する必要があります。 例えば以下のような実装を行います: 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");
  }
  

- getKeys の返すキーに重複した値が存在する場合には最初に見つかったひとつだけが返されます。 該当するキーが見つからなかった場合には例外が投げられます。 unspecified メソッドをオーバーライドすることによって独自の処理を適用することができます。 リクエストがキャンセルされた(html:cancel ボタンが押された)場合には、 カスタマイズ用途で準備されている cancelled メソッドが代わりに利用されます。

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.

翻訳者:
日置 聡
校正者:
翻訳状況:
初稿(校正者募集中)

フィールドの概要
protected  java.util.Map keyMethodMap
          リソースキーからメソッド名を検索するための情報。
protected  java.util.Map localeMap
          リソースの値からリソースのキーを検索するためのマップ。
 
クラス org.apache.struts.actions.DispatchAction から継承したフィールド
clazz, log, messages, methods, types
 
クラス org.apache.struts.action.Action から継承したフィールド
defaultLocale, servlet
 
コンストラクタの概要
LookupDispatchAction()
           
 
メソッドの概要
 ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          指定されたHTTP リクエストを処理し、対応する HTTP レスポンスを返します(または HTTP レスポンスを生成する他の Web コンポーネントに対して転送を行います)。
protected abstract  java.util.Map getKeyMethodMap()
          リソースキーからメソッド名を取得するマッピングを用意します。
protected  java.lang.String getLookupMapName(javax.servlet.http.HttpServletRequest request, java.lang.String keyName, ActionMapping mapping)
          クライアントからのリクエストのロケールを考慮してメソッド名を捜し出します。
protected  java.lang.String getMethodName(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String parameter)
          与えられたパラメータを用いて、メソッド名を返します。
private  java.util.Map initLookupMap(javax.servlet.http.HttpServletRequest request, java.util.Locale userLocale)
          リクエストの際に各ロケールが最初に利用された場合に、逆順に検索を行うための Map を生成します。
 
クラス org.apache.struts.actions.DispatchAction から継承したメソッド
cancelled, dispatchMethod, getMethod, unspecified
 
クラス 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
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

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.

コンストラクタの詳細

LookupDispatchAction

public LookupDispatchAction()
メソッドの詳細

execute

public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws java.lang.Exception
指定されたHTTP リクエストを処理し、対応する HTTP レスポンスを返します(または HTTP レスポンスを生成する他の Web コンポーネントに対して転送を行います)。 処理をどこにどうやって転送すべきかが記述された ActionForward インスタンスまたは、レスポンスが既に完了している場合には null を返します。
Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed.

オーバーライド:
クラス DispatchAction 内の execute
パラメータ:
mapping - このインスタンスを選択する際に使用された ActionMapping
The ActionMapping used to select this instance
request - 処理中のHTTPリクエスト
The HTTP request we are processing
response - 生成中のHTTPレスポンス
The HTTP response we are creating
form - このリクエストに対応する ActionForm(もしあれば)
The optional ActionForm bean for this request (if any)
戻り値:
処理をどこにどうやって転送すべきかの情報
Describes where and how control should be forwarded.
例外:
java.lang.Exception - 例外が発生した場合
if an error occurs

initLookupMap

private java.util.Map initLookupMap(javax.servlet.http.HttpServletRequest request,
                                    java.util.Locale userLocale)
リクエストの際に各ロケールが最初に利用された場合に、逆順に検索を行うための Map を生成します。 該当のモジュールに設定されたすべての MessageResources からメッセージキーを検索します。
This is the first time this Locale is used so build the reverse lookup Map. Search for message keys in all configured MessageResources for the current module.


getKeyMethodMap

protected abstract java.util.Map getKeyMethodMap()
リソースキーからメソッド名を取得するマッピングを用意します。
Provides the mapping from resource key to method name.

戻り値:
リソースキー/メソッド名 のマッピング情報を持つマップ
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.

パラメータ:
request - 処理中のHTTPリクエスト
The HTTP request we are processing
keyName - プロパティのキーに使用されるパラメータ名
The parameter name to use as the properties key
mapping - このインスタンスを選択する際に使用された ActionMapping
The ActionMapping used to select this instance
戻り値:
国際化に対応したメソッド名
The method's localized name.
例外:
javax.servlet.ServletException - keyName が解決できなかった場合
if keyName cannot be resolved
導入されたバージョン:
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.

オーバーライド:
クラス DispatchAction 内の getMethodName
パラメータ:
mapping - このインスタンスを選択する際に使用された ActionMapping
The ActionMapping used to select this instance
form - このリクエストに対応する ActionForm(もしあれば)
The optional ActionForm bean for this request (if any)
request - 処理中のHTTPリクエスト
The HTTP request we are processing
response - 生成中のHTTPレスポンス
The HTTP response we are creating
parameter - ActionMapping 内のパラメーターの名前
The ActionMapping parameter's name
戻り値:
メソッド名
The method's name.
例外:
java.lang.Exception
導入されたバージョン:
Struts 1.2.0


このドキュメントは、Ja-Jakartaにより訳されました。コメントがある場合は、report@jajakarta.orgまでお願いします。
Copyright (C) 2000-2004 - Apache Software Foundation