You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Michael Jouravlev (JIRA)" <ji...@apache.org> on 2006/08/28 20:17:31 UTC

[jira] Commented: (STR-1906) [taglib] html:cancel alteration to allow for default enter key form submission

    [ http://issues.apache.org/struts/browse/STR-1906?page=comments#action_38044 ] 
            
Michael Jouravlev commented on STR-1906:
----------------------------------------

I suggest closing this issue with "Won't Fix".

HTML spec does not define a specific behavior for the "default submit" situation, i.e. when a form is submitted by hitting Enter on an input field instead of explicit activating of a submit button. Therefore, different browsers act differently and your assumption that the last button "wins" is browser-dependent at least. Moreover, I observed different behavior in the same browser, so rearranging the buttons is not an answer.

I suggest using EventDispatchAction or EventActionDispatcher (Struts 1.2.9+) to process events from button clicks. In case of a default submit a browser may not send any button event, for this situation one can define a hidden field containing a default event. When defining events in an action mapping define the default event last, like:

<action path = "/mydispatchaction"
  type = "com.acme.MyEventDispatchAction"
  parameter = "okEvent=store,cancelEvent=cancel,defaultEvent=cancel,default=unspecified"
  validate = "false">

Here "defaultEvent" is default event defined in a hidden field. If form is submitted with default submit and no default events are defined in a hidden field, then "default" event will be tiggered and "unspecified" method will be called.

Also, if you use <html:cancel> tag for your Cancel button, it will be processed earlier than other button events.

> [taglib] html:cancel alteration to allow for default enter key form submission
> ------------------------------------------------------------------------------
>
>                 Key: STR-1906
>                 URL: http://issues.apache.org/struts/browse/STR-1906
>             Project: Struts 1
>          Issue Type: Improvement
>          Components: Taglibs
>    Affects Versions: 1.1 Final
>         Environment: Operating System: All
> Platform: All
>            Reporter: Marcus Breese
>         Assigned To: Struts Developers
>            Priority: Minor
>         Attachments: Cancel.patch, CancelTag.java.patch, cancelTag_tld_javascript.diff
>
>
> If you use the html taglib to create the submit and cancel tags, you have to be
> careful of the order, as if you are in a form and you hit the enter key, the
> form will be submitted or cancelled based upon the last submit/cancel tag used.
> Meaning if the order is like this:
> (Submit) (Cancel)
> the form will be cancelled
> if the order is:
> (Cancel) (Submit)
> the form will be submitted.
> For pure aesthetic reasons, I prefer to put the cancel button last (also, that
> is how most of my users like it), but I also like to hit the enter key to submit
> forms... 
> I've written the following patch to org.apache.struts.taglib.html.CancelTag to
> rewrite the cancel submit button to be a combination of a "button" and a hidden
> form field.
> This requires NO CHANGE to current jsp pages.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira