I want to use a form that has two submit buttons. Each button calls the same form action, but submits a different value for one of its fields. To do this, I have been successful using the s:submit button as follows:
<s:submit name="submitType" value="foo" type="button">Click me!</s:submit>
In the above, the text that appears in the button (“Click me!”) is different from the value that gets submitted by the form (“foo”). However, this is not the case for the dojo submit tag with the exact same attributes:
<sx:submit name="submitType" value="bar" type="button">Or click me!</sx:submit>
With the above tag, the button’s text is “bar” and the words “Or click me!” appear beside it.
For good measure, I’ll throw in the HTML that gets generated by each of these buttons:
<!-- (Using the simple form theme) -->
<!-- The s:submit tag: -->
<button type="submit" id="submit-sandbox_submitType" name="submitType"
value="foo">
Click me!
</button>
<!-- The sx:submit tag -->
<input type="button" dojoType="struts:Bind" events="onclick"
id="widget_1100841481" label="bar" name="submitType" value="bar" />
<script language="JavaScript" type="text/javascript">
djConfig.searchIds.push("widget_1100841481");
</script>
Or click me!
It seems that the sx:submit button’s type attribute isn’t working as it is described in the documentation! 🙁 Any thoughts?
I found an answer to my own question in the Struts 2 cookbook. When you use multiple submit buttons to input submit different field values, a recommended approach is to use a separate boolean field for each submit button instead of a single String field for all of the submit buttons. This way, the value attribute of the button doesn’t matter as far as what gets submitted to the action, so I can use it to display whatever text I want.
http://struts.apache.org/2.2.3/docs/multiple-submit-buttons.html