Set current date in af:inputDate on double click using javascript in ADF

Sharing is Caring

This post is about a question that is asked on OTN forum. In this post, I’ll show you that how we can set current date in af:inputDate component on double click of the mouse. For this, we need to use a simple javascript function.

Here we have an inputDate component on the page and added javascript function as a resource in the page. See page XML source

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="SetCurrentDate.jspx" id="d1">
            <af:resource type="javascript">
              function setDate(evt) {
                  var comp = evt.getSource()
                  comp.setValue(new Date());

              }
            </af:resource>
            <af:form id="f1">
                <af:inputDate label="Label 1" id="id1">
                    <af:clientListener method="setDate" type="dblClick"/>
                </af:inputDate>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

All done, as you can see that the javascript function is called using clientListener on double click event of input date component.

Set Current Date using Javascript

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

1 thought on “Set current date in af:inputDate on double click using javascript in ADF”

  1. Are you aware of any declarative solution to always have the time part of an input-date component defaulted to 00:00:00 or 23:59:59? We can set the or . However, with this approach, the user loses the ability to change the time from the component.

    Regards.

Leave a Reply

Your email address will not be published. Required fields are marked *