|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectorg.apache.struts.action.Action
org.apache.struts.actions.DispatchAction
org.apache.struts.actions.LookupDispatchAction
サブクラスにてマッピングされた execute メソッドに対して処理を割り振る機能を持つ抽象
Action です。
これは HTML フォームが同名で複数のサブミットボタンを持っている場合に有用です。
ボタンの名称は対応する ActionMapping の parameter
プロパティにて指定されます。
このアクションを使用する場合には、以下のようなエントリを
struts-config.xml ファイルに記述します:
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 を用意します:
button.add=Add Record
button.delete=Delete Record
また、JSPには以下のようなフォーマットのサブミットボタンを用意します:
<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 |
| フィールドの詳細 |
protected java.util.Map localeMap
protected java.util.Map keyMethodMap
| コンストラクタの詳細 |
public LookupDispatchAction()
| メソッドの詳細 |
public ActionForward execute(ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.lang.Exception
ActionForward インスタンスまたは、レスポンスが既に完了している場合には
null を返します。
ActionForward instance describing where and how
control should be forwarded, or null if the response has
already been completed.
DispatchAction 内の executemapping - このインスタンスを選択する際に使用された ActionMapping
request - 処理中のHTTPリクエスト
response - 生成中のHTTPレスポンス
form - このリクエストに対応する ActionForm(もしあれば)
java.lang.Exception - 例外が発生した場合
private java.util.Map initLookupMap(javax.servlet.http.HttpServletRequest request,
java.util.Locale userLocale)
protected abstract java.util.Map getKeyMethodMap()
protected java.lang.String getLookupMapName(javax.servlet.http.HttpServletRequest request,
java.lang.String keyName,
ActionMapping mapping)
throws javax.servlet.ServletException
request - 処理中のHTTPリクエスト
keyName - プロパティのキーに使用されるパラメータ名
mapping - このインスタンスを選択する際に使用された ActionMapping
javax.servlet.ServletException - keyName が解決できなかった場合
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
DispatchAction 内の getMethodNamemapping - このインスタンスを選択する際に使用された ActionMapping
form - このリクエストに対応する ActionForm(もしあれば)
request - 処理中のHTTPリクエスト
response - 生成中のHTTPレスポンス
parameter - ActionMapping 内のパラメーターの名前
ActionMapping parameter's namejava.lang.Exception
|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||