0

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?

gene b.
  • 10,512
  • 21
  • 115
  • 227
  • https://stackoverflow.com/a/20746418/573032 – Roman C Aug 09 '19 at 21:27
  • This doesn't answer my question. I'm not asking how to handle a single Submit button (either with a Form `action=` or a single Submit's `method=`). I'm asking how to map **multiple** Submit buttons pointing to different methods in a Form. – gene b. Aug 10 '19 at 14:35
  • 1
    If you know how to invoke a method on a submit button then you should think to have multiple submit buttons that are bound to the methods of the action class. See https://stackoverflow.com/a/14467399/573032 – Roman C Aug 13 '19 at 21:14

0 Answers0