Requirement: I have an af:inputDate field in which I want to default the date value as soon as we focus on the InputDate component.
Solution: For solution of the above requirement follow the steps as shown below:
Step 1: Create an Oracle ADF Fusion Web Application. Create a demo.jspx page in the ViewController project.
Step 2: Drag and drop af:inputDate and set label=”Select Date”
Drag and drop af:resource and set type=”javascript”. The af:resource will be inside af:document
Write the below JavaScript function inside the af:resource
function disableKeyboardInput(event) { var component = event.getSource() component.setValue(new Date()); }
Drag and drop af:clientListener inside af:inputDate and set method=”disableKeyboardInput” and type=”focus”
Thus, the complete code for demo.jspx page is shown below:
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="" version="2.1" xmlns:f="" xmlns:af=""> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="demo.jspx" id="d1"> <af:resource type="javascript"> function setDefaultDate(event) { var component = event.getSource() component.setValue(new Date()); } </af:resource> <af:form id="f1"> <af:inputDate label="Select Date" id="id1"> <af:clientListener method="setDefaultDate" type="focus"/> </af:inputDate> </af:form> </af:document> </f:view> </jsp:root>
Save and run the application. Thus, the ran application is shown below:
In the above af:inputDate field as soon as we focus on the component it will default the System date as the default Date value.
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
383 total views, 1 views today