Can we select a day twice (one after another)
rktest05 Sep 25, 2008 1:31 PMHi,
This is what I'm trying to do: I want to display a calendar (monthly with popup=false) and the user can select a day. When the user selects a day, the background color will change do red. if he selects it again, the background color will change to red. So, it will alternate between green and red.
I've got most of it working with the sample code from Organizer Calendar demo src code (with the dataModel). However, one isssue I'm running into is: if I select a day, I cannot reselect it immediately. However, I can select another day and come back to reselect the old one. Basically, I cannot select a day twice one after another. How do I go about doing this?
How do I enable such that user can select and select a day?
Here is my code:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
.ecol1 { vertical-align: top; padding-right : 25px }
.ecol2 { vertical-align: top; border-left: #ACBECE 1px solid; padding-left : 10px }
.rich-calendar-tool-btn{
font-family: Arial, Verdana;
}
.bk { background-color: red }
.bookedbk { background-color: red }
.availbk { background-color: green }
<f:view>
--Part of my CalendarDataModelImpl as follows:---
public class CalendarDataModelImpl implements CalendarDataModel {
/* (non-Javadoc)
* @see org.richfaces.component.CalendarDataModel#getData(java.util.Date[])
*/
private CalendarDataModelItem[] items;
private String currentDescription;
private String currentShortDescription;
private Date currentDate;
private boolean currentDisabled;
private Map<String, CalendarDataModelItem[]> monthMap = new HashMap<String, CalendarDataModelItem[]>();
/* (non-Javadoc)
* @see org.richfaces.model.CalendarDataModel#getData(java.util.Date[])
*/
public CalendarDataModelItem[] getData(Date[] dateArray) {
if (dateArray == null) {
return null;
}
//check if the monthmap already exists in memory
String month = dateArray[0].getMonth() + "" + dateArray[0].getYear();
if (monthMap.containsKey(month)) {
items = (CalendarDataModelItem[])monthMap.get(month);
return items;
}
items = new CalendarDataModelItem[dateArray.length];
for (int i = 0; i < dateArray.length; i++) {
items = createDataModelItem(dateArray);
}
//put the month info in memory
monthMap.put(month, items);
return items;
}
/**
* @param date
* @return CalendarDataModelItem for date
*/
protected CalendarDataModelItem createDataModelItem(Date date) {
CalendarDataModelItemImpl item = new CalendarDataModelItemImpl();
Calendar c = Calendar.getInstance();
c.setTime(date);
item.setDay(c.get(Calendar.DAY_OF_MONTH));
item.setEnabled(true);
item.setStyleClass("availbk");
return item;
}
/* (non-Javadoc)
* @see org.richfaces.model.CalendarDataModel#getToolTip(java.util.Date)
*/
public Object getToolTip(Date date) {
// TODO Auto-generated method stub
return null;
}