I have a Struts 2 Form whose form action is mapped to the processForm
Action, with multiple Submit buttons pointing to specific methods in that Form Action using method=
.
<s:form id='myForm' action="processForm">
<!-- ... -->
<s:submit id="method1" method="method1" name="method1" value="1"/>
<s:submit id="method2" method="method2" name="method2" value="2"/>
<s:submit id="method3" method="method3" name="method3" value="3"/>
</s:form>
Suppose the Action class that handles it is MyFormAction
:
public class MyFormAction extends BaseAction {
public String method1() {
// ...
}
public String method2() {
// ...
}
public String method3() {
// ...
}
}
I found that in struts.xml, if I just specify the first method, all button clicks resolve successfully, without me adding specific blocks for the other methods:
<action name="processForm" class="myapp.action.MyFormAction" method="method1">
<result name="success" type="redirectAction">
<param name="actionName">homeaction</param>
</result>
</action>
<!-- No other mappings defined for method2/method3, but they work -->
If there is no action mapping at all for processForm
then everything fails.
So my question is, what is the proper way to define multi-Submit mappings inside a single Form Action in struts.xml? Do I just go ahead and manually define every single method explicitly, even though it works "implicitly"? Or am I doing this wrong?