Affects Version/s: 5.0.15
Fix Version/s: 184.108.40.206
The Submit component has two major deficiencies:
1) You cannot use an image submit ( <input type="image" /> )
2) You cannot pass any context into the button's "selected" event handler.
Issue 1 currently requires you to create your own submit button type, though this is simple if you don't mind copy/pasting the current Submit class and changing one line.
Issue 2 is a much bigger problem. If you have a submit button in a loop and need to know (for example) which item was current in the loop when it was rendered, you have to set "defer" to false, then record the context information in your onSelected handler. You often can't perform a useful action directly in your deferred onSelected handler because you shouldn't change the structure of your bound data in the middle of a form submit, or because you should not perform your action until you're assured the form has validated.
So, you now have to record the context that you need to perform the action, PLUS the action that needs to be performed, and then perform it all inside of your onSuccess handler! Frankly, this seems so inelegant as to have been an oversight.
On the Tapestry Wiki, at http://wiki.apache.org/tapestry/Tapestry5SubmitContextComponent there is a basic implementation, though it has several weaknesses:
1) It was written for 5.0.4 and doesn't compile without changing a few minor things, nor does it support RenderDisabled.
2) It only supports a single context parameter and it makes no effort to properly encode it when rendered to the client.
So, based on the concept used on the wiki code (namely, using a <hidden> field to store the context) I made a few small modifications to the Tapestry 5.0.11 Submit.java class that I will attach to this issue.
I grant ownership of the attached code to the Apache Software Foundation.