Disabling Past And Future Dates in Date Picker ADF

Hi All,

In this post I am going to show you how you can disable the past dates and future dates in date picker in ADF.

To disable the past date for af:inputDate component we have one property "minValue". If you want to disable all the dates before current date then you can do the following.

First of all write a method in your bean which will return you the current date in the format "yyyy-MM-dd" as shown below.


  public Date getCurrentSystemDate() {
    try {
    Calendar now = Calendar.getInstance();
    java.util.Date date = now.getTime();
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String currentDate = formatter.format(date);
    return formatter.parse(currentDate);
    } catch (Exception e) {
    return null;
    }
    } 


Now bind this method to minValue property of af:inputDate component.


 <af:inputDate value="#{bindings.HireDate.inputValue}"
                      label="#{bindings.HireDate.hints.label}"
                      required="#{bindings.HireDate.hints.mandatory}"
                      shortDesc="#{bindings.HireDate.hints.tooltip}" id="id1"
                      minValue="#{backingBeanScope.TestBean.currentSystemDate}">
          <f:validator binding="#{bindings.HireDate.validator}"/>
          <af:convertDateTime pattern="#{bindings.HireDate.format}"/>

 </af:inputDate>


For disbling future dates do the same thing for the property maxValue.

once you run the page you can see that the past dates are disabled as shown below:





Happy Coding :)

Comments

  1. hi kunal...it is very helpful..

    ReplyDelete
  2. AnonymousMay 29, 2015

    Hi Kunal,

    Thanks for this info. I've a specific requirement to disable few selected days only. Like based on a parameter value, I wish to disable only Fridays or Wednesday. Kindly suggest if you're aware of any such solution.

    Sid

    ReplyDelete
  3. Thanks Kunal. It is really helpful..

    ReplyDelete
  4. HI Kunal,
    I have tried the same.
    My requirement was to disable al dates prior to sysdate.
    But when I select the current date (say 06/28/2016), it prompts saying please enter a date equal to or greater than 28/06/2016.
    eg . 06/29/2016

    So the issue is that using the minValue property, I was able to disable past dates on the datepicker, but the date field validator does not allow the sysdate to be entered. Only a date after sysdate is allowed.
    Even though themessage suggests enter current date or a future one.

    Did you encounter this issue.

    Kindly help.

    Thanks,
    Ratnadeep

    ReplyDelete
  5. Hi Ratnadeep,

    Use the same format it will work.

    ReplyDelete

Post a Comment

Popular posts from this blog

Setting up the environment for Angular2 and Hello World Example in Angular2

Showing number of rows or row count on top and bottom of table in ADF.

Build a Simple ReactJS application using react-cli