JSF 2.0 Ajax问题

I have some <h:inputText> on my form and two <h:commandButton>s, one commandbutton submits the form in a classic manner and the other one has a <f:ajax>, how can I prevent the form from submitting when the user presses Enter key in one of my inputs which triggers the second button?

If you don't have textareas in your form, just add the following to the <h:form>.

<h:form onkeypress="return event.keyCode != 13">

The Enter key has the key code 13, so the above returns false to the form whenever it is been pressed, so the default action won't take place anymore.

However, if you have textareas in your form (<h:inputTextArea> and on), where you'd like to have the Enter key to function as usual, then you need to put the onkeypress attribute in all non-textarea input fields instead. You can use JS/jQuery for this to minimize code duplication.