Struts 1.2 を使ったアイデア

  1. LookupDispatchAction + ForwardAction の混ざったようなもの(LookupForwardAction とでもする)
  2. MappingDispatchAction

を組み合わせれば,一つの画面に複数のボタンがあり,それぞれで Validation を分けたいときも結構楽に書けるかも?

LookupForwardAction

package example;

・・・

public class LookupForwardAction extends LookupDispatchAction {

	public ActionForward execute(・・・) throws Exception {
		String parameter = mapping.getParameter();
		String methodName = getMethodName(mapping, form, request, response, parameter);
		ActionForward forward = new ActionForard(mapping.getPath() + "/" + methodName);
		forward.setContextRelative(true);
		return forward;
	}

	protected Map getKeyMethodMap() {
		Map result = new HashMap();
		result.put("button.create", "create");
		result.put("button.update", "update");
		result.put("button.delete", "delete");
		・・・
	}
	
}

struts-config.xml

<action path="/user"
		type="example.LookupForwardAction"
		parameter="actions"/>

<action path="/user/create"
		type="example.UserAction"
		parameter="create">
	<forward name="success" path="・・・"/>
</action>

<action path="/user/update"
		type="example.UserAction"
		parameter="update">
	<forward name="success" path="・・・"/>
</action>

JSP は LookupDispatchAction を使っていたときと同じような感じ

<html:form action="/user.do">
・・・
<html:submit property="actions">
<bean:write message="button.create">
</html:submit>
<html:submit property="actions">
<bean:write message="button.update">
</html:submit>
・・・
</html:form>

これで,Javascript で form.action の URL を切り替えたりしなくても,MappingDispathAction の恩恵が受けられる(はず...)