Alternative to p:defaultCommand


Using the standard JSF h:commandLink has a limitation when wanting to submit the form when the enter button is pressed. This solution uses the javascript keyCode keyboardevent built into browsers. When keyCode 13 (or enter key) is pressed the h:commandLink (which renders a <a> tag) is submitted. This will call its action that has been attached to the component.

<h:inputText value="#{backingBean.searchString}" onkeydown="if (event.keyCode === 13) {
return false;
<h:commandLink id="submitSearchButton" action="#{backingBean.submit}" value="submit"/>

This solution is most useful when the Primefaces defaultCommand component is not available.