Often we might want to control the calendar object of our view from the server side.
For instance I needed the user to be prevented from selecting the date before today. This was achieved using the CalendarDataModel.
Simply use the following steps:
For instance I needed the user to be prevented from selecting the date before today. This was achieved using the CalendarDataModel.
Simply use the following steps:
Step 1) In your view with
dataModel="#{calendarDataModel}" mode="ajax"
--here dataModel property indicates the model to be used. The mode defines whether to operate on client mode or on ajax mode. To use datamodel we need to have ajax mode to be used.
Step 2) Now register the bean named calendarDataModel in your applicationContext.xml(for spring application) or in faces-config.xml in JSF based application or wherever appropriate(depending on the requirement)
Step 3) Now Define the classes CalendarDataModelImpl and CalendarDataModelItemImpl as shown below:
Class CalendarDataModelImpl.java
When the calendar item is loaded on the view the main method that will be triggered is:
public CalendarDataModelItem[] getData(Date[] dateArray) {
........
}
So we can customize our bean as per our requirement.
Class CalendarDataModelItemImpl.java
This class will access each and every element (item) of the date element. So we can change the corresponding attributes of the element if required.