Multiple submit buttons
This cost me a couple of hours of screwing around. In the code I was working with, there were originally two forms. The second form existed simply as a target for the cancel button. Since that seemed kind of pointless, I came up with a way to have the two different buttons submit to different places:
<s:form id="blah" name="blahForm" action="save" method="post" validate="true" namespace="/blah">
<s:submit value="Save" type="button" />
<s:submit value="Cancel" type="button" action="cancel" />
</s:form>This worked fine (perfectly) in Firefox and IE7, but my testers discovered that it didn't seem to work at all in IE6 -- in other words, the save didn't "take".
After digging, I realized this was because the cancel method was being invoked in the action instead of the save method. This made absolutely zero sense. After some digging, I found this link:
Among other things, this page mentions:
IE submits all buttons in your form: Yes! I mean what were they thinking?
To clarify: You have three different buttons in your form, e.g. "save",
"delete" and "insert". If you press one of them all corresponding values
will be submitted! Which acutally means you can't decide which button was
clicked on the server side. One workaround would be to use hidden submit
fields which are being filled by the button's onclick handler.Whoa. That's a pain. I went back to the Struts2 documentation and found that the documentation for s:submit actually mentions this (well, sort of):
Please note that the button type has advantages by adding the possibility
to seperate the submitted value from the text shown on the button face, but
has issues with Microsoft Internet Explorer at least up to 6.0That implied this solution, which seems to work. I use 'input' rather than 'button' and then move the action name down onto the buttons rather than having a default on the form.
<s:form id="blah" name="blahForm" method="post" validate="true" namespace="/blah">
<s:submit value="Save" type="input" action="save" />
<s:submit value="Cancel" type="input" action="cancel"/>
</s:form>This apparently solves the problem.