*
The moose likes JSF and the fly likes Form and commandButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Form and commandButton" Watch "Form and commandButton" New topic
Author

Form and commandButton

Johan Rignas
Ranch Hand

Joined: Jul 17, 2011
Posts: 30
Hi. I have a Form containing some inputTexts and one commandButton. Is there any simple way to make the "Enter"-key make the commandButton to trigger? It feels very very inefficient to have a "onkeydown" listeners for every textfield that listens to every key press.... Any ideas?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

Yes, but there's a catch. In most web browsers, when you have a single submit button, pressing "Enter" will submit the form.

However, the old offender: Internet Explorer, won't do that. So you have to put in browser-specific hacks. They're just gnarly enough that I don't remember the details, but you can Google for them. It's an HTML problem, not a JSF problem, so non-JSF apps have the save troubles.


Customer surveys are for companies who didn't pay proper attention to begin with.
Johan Rignas
Ranch Hand

Joined: Jul 17, 2011
Posts: 30
I´m not convinced. I´m using Chrome and this dose not trigger the button when I press "Enter" in selected textField:

I´m missing something? Should this work?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

Maybe Chrome is "IE Compatible"???
Johan Rignas
Ranch Hand

Joined: Jul 17, 2011
Posts: 30
Probably. But when trying the same code with firefox the "Enter"-key still dose not trigger the "action"....
My only guess is that I´m missing something...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

If the page is literally as you displayed it, it's probably because you have no actual input (no "value=" reference on the inputText element).
 
Consider Paul's rocket mass heater.
 
subject: Form and commandButton
 
Similar Threads
h:form vs a4j:form
JSF2.0, Possibility to align Components in panelgrid
JSF with Javascript
JSF1007: Duplicate component ID j_id10 found in view
bean property not being updated