Disabling Holidays and weekends days in af:inputDate component

Hello,

In this post, I would like to explain the disabling functionality on specific dates in input date component in adf.
















in the above date component i have disabled the Friday and Saturdays in every month and 1st 2nd 5th dates are the holidays as per my calendar so i disabled this list of dates.

In order to achieve this functionality we need a special class that implements the "DateListProvider" interaface with one overriden method is as follows.

package com.tata.guru.view;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.faces.context.FacesContext;

import org.apache.myfaces.trinidad.model.DateListProvider;

public class DatePageBean  implements DateListProvider {
    public DatePageBean() {
        super();
    }
    public List<Date> getDateList(FacesContext facesContext, Calendar calendar,
                                  Date date, Date date1) {
        List holidays = new ArrayList<Date>();
        try{
            SimpleDateFormat simpleDate = new SimpleDateFormat("dd/MM/yyyy");
            holidays.add(simpleDate.parse("01/01/2015"));
            holidays.add(simpleDate.parse("01/02/2015"));
            holidays.add(simpleDate.parse("01/03/2015"));
            holidays.add(simpleDate.parse("01/04/2015"));
            holidays.add(simpleDate.parse("01/05/2015"));
            holidays.add(simpleDate.parse("01/06/2015"));
            holidays.add(simpleDate.parse("01/07/2015"));
            holidays.add(simpleDate.parse("19/07/2015"));
            holidays.add(simpleDate.parse("02/03/2015"));
            holidays.add(simpleDate.parse("06/03/2015"));
            holidays.add(simpleDate.parse("05/03/2015"));
        }
        catch(Exception e){
            e.printStackTrace();
            return Collections.emptyList();
        }
        return holidays;
    }
}

And on <af:inputDate> component code

 <af:inputDate label="Due Date" id="id1"
                        disabledDays="#{viewScope.DatePageBean}"
                        disabledDaysOfWeek="fri and sat"/>

disabledDays : This accepts the list of disabled dates ( To disable specific dates which returns as a list ).
disabledDaysOfWeek : This accepts the weekdays ( I have passed fri and sat as weekends to disable on Calender )


Note: Plz ignore spelling and grammar mistakes!

Download @ DisabledDates

Thanks & Regards,
Guravaiah Tata

Comments

Post a Comment

Popular posts from this blog

Common Errors - Invoking Oracle Stored procedure from MuleSoft 4.0 - DateTime formats and Default values

JDev/ADF -- Programmatically Deleting selected rows in ADF Table

Apache Camel K Installation Process In a nutshell