Please disable your adblock and script blockers to view this page

Search this blog

Tuesday 29 July 2014

Showing highlighted holiday calendar in af:inputDate date picker (ADF 12.1.3)

Hello All
This post is about showing highlighted days for holidays in af:inputDate and user must not be able to select these dates
here i am using Jdeveloper 12.1.3
you can do this using af:calendar
https://blogs.oracle.com/adf/entry/display_holiday_name_in_af
but i have a requirement to show holidays while user selects date using af:inputDate

so for this requirement first step is easy to do and there is lots of post about disabling specific days in calendar of af:inputDate

Step 1. Disable specific days -
  • you can see there is property in af:inputDate for setting disabled days, this filed takes a value of type List supported by DateListProvider interface




  • for this purpose i have created a bean that implements methods of DateListProvider , in Overridden method i have defined a list that contains dates of holidays that i want to disable in af:inputDate

  • package holiday.view.bean;
    
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;
    
    import javax.faces.context.FacesContext;
    
    import org.apache.myfaces.trinidad.model.DateListProvider;
    
    public class HolidayBean implements DateListProvider {
        public HolidayBean() {
        }
    
        @Override
        public List<Date> getDateList(FacesContext facesContext, Calendar calendar, Date date, Date date2) {
            List<java.util.Date> holiDay = new ArrayList();
            holiDay.add(new Date("27-July-2014"));
            holiDay.add(new Date("29-July-2014"));
            holiDay.add(new Date("10-Aug-2014"));
            holiDay.add(new Date("25-Dec-2014"));
            holiDay.add(new Date("01-Jan-2015"));
            holiDay.add(new Date("22-Oct-2014"));
            holiDay.add(new Date("23-Oct-2014"));
            holiDay.add(new Date("24-Oct-2014"));
    
            return holiDay;
            //return Collections.emptyList();
        }
    }
    

  • attached this bean to disabledDays property of af:inputDate


  • now first part is done we can see all holidays as disabled in calendar of af:inputDate

Step 2. Highlight disabled holidays -
  • but it is not easy to find holidays as all are in grey, so i have to highlight all disabled days , so for this requirement , create a skin in viewController project and write this

  • af|chooseDate::regular-day:disabled{
        background-color: red;
        color: ButtonFace;
    }
    

  • af:chooseDate is used because internally af:inputDate opens af:chooseDate as date picker so i have to change property of af:chooseDate, now run your application

Happy Learning :)

4 comments :

  1. How to make it read holiday from DB table

    ReplyDelete
    Replies
    1. You can read holiday date from DB table and add it to List , It's simple

      Delete
  2. How to restrict date picker for current year?

    ReplyDelete
    Replies
    1. You can set min and max value for date selector

      Delete