aspose file tools*
The moose likes Struts and the fly likes Enter key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Enter key" Watch "Enter key" New topic
Author

Enter key

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi all,

Am using Struts framework and i have 3 buttons on the page. My action class extends DispatchAction.
How do I make the form submit for a particular action on pressing the enter key.

Pls this is urgent

Thx in advance
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

This is not really a Struts-specific issue.

A browser will usually submit the form using the first button it rendered to the page when the Enter key is pressed. To get around this, you will need a javascript solution OR design your page so that the button you want pressed upon an Enter keypress is the first button in the text of your html.


A good workman is known by his tools.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
you need to use javascript to submit your form. the script should:
1. detects keypressed (check for event.key == 13; look online for samples
(2. your DispatchedAction parameter in an unset hidden form field - inside the form, not done by the javascript)
3. set the parameter value to the name of the DispatchedAction you want to call
4. form.submit()

to accomodate the clicking of the the other 2 buttons, you only have to have another javascript submit method doing step 2 and 3 above. of course the form fields must be of type 'button' and you call the submit method 'onclick'.

-/a


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enter key