We saw at many popular website we can submit the form by pressing enter key in the input field. Like enter userid and password and press enter key to submit values.
Here I will explain how we can implement this functionality in Oracle ADF 11g.
Here I am using af: panelFormLayout component in a jspx page. I have used four input fields and want the form should be submitted when I press enter key in the last input field (i.e. email address).
To enable this functionality we can use javaScript on the email address input field. Drag and drop the clientListener component on the email address input field. Provide method name (e.g. submitForm) and select keyPress as event type.
Add below code inside af:document tag in the jspx page :-
<af:resource type="javascript">
function submitForm(event) {
if (event.getKeyCode() == AdfKeyStroke.ENTER_KEY) {
var source = event.getSource();
var myButton = source.findComponent("cb1");
var actionEvent = new AdfActionEvent(myButton);
actionEvent.forceFullSubmit();
actionEvent.noResponseExpected();
actionEvent.queue();
}
}
</af:resource>
Using above code we cause Submit button to be clicked and the action that was supposed to perform on button click, will be done when enter key is pressed.
• getKeyCode() returns the javaScript code for each key pressed by the user.
• Here “cb1” is the id of command button which should be submitted.
• forceFullSubmit() specifies that the event must be delivered with a full page submit regardless of what isPartial() returns
• noResponseExpected() specifies that this event is not expected to produce a response handled by the framework, such as when export contents are streamed to Excel or when a file is downloaded.
Enter values for all four required fields and press enter key in the email address field.
By pressing enter key in the last field (email address) values will get submitted and actionListener/action associated with Submit button will be called.