Controlling form submission using defaultCommand
The Enter key makes form submission so easy that users always tend to use it. The most intuitive way is that the user can enter some text or make some changes to the existing text and then hit the Enter key to submit the form. But what command component will submit the form if we have more than one of them? Browsers, especially Internet Explorer, behave differently here. The defaultCommand
component solves this problem by normalizing the command (for example, button
or link
) that submits the form when the Enter key is hit.
In this recipe, we will discuss p:defaultCommand
in detail. We will implement p:selectOneMenu
for dynamic selection of the command button used for form submission when the Enter key is hit.
How to do it…
We intend to save the chosen command button used for form submission in a backing bean. To achieve this, we need p:selectOneMenu
with listed command buttons (their IDs) and an attached p:ajax
behavior event. Such an...