I am trying to disable all the date in the DatePicker
GWT component, here is my sample of code :
datePicker.addShowRangeHandler(new ShowRangeHandler<Date>() {
public void onShowRange(ShowRangeEvent<Date> event) {
System.out.println("First date : " + event.getStart());
System.out.println("Last date : " + event.getEnd());
System.out.println("First date from date picker : " + datePicker.getFirstDate());
System.out.println("Last date from date picker : " + datePicker.getLastDate());
// Disable all the date s开发者_开发百科hown by the Calendar
List<Date> dateList = new ArrayList<Date>();
Date currentDate = event.getStart();
while(!currentDate.after(datePicker.getLastDate())) {
Date updateDate = CalendarUtil.copyDate(currentDate);
dateList.add(updateDate);
CalendarUtil.addDaysToDate(currentDate, 1);
}
for(Date date : dateList) {
System.out.println("Date selected : " + date);
System.out.println("date visibility : " + datePicker.isDateVisible(date));
}
}
});
Date visibility is always false , it keep telling me that all the date are not visible, but it should be true since it' between the first date and last date, anybody know a way to disable date in calendar?, so if tried the method setTransientOnEnables()
on the datePicker for any of the date I keep getting an exception as the date arenot visible.
I had tried also impleenting my own DefaultClendarView
but it requires protected class which is not available by GWT.
I had similar problems. I was trying to disable dates in the future. I eventually found out that start and end dates are final variables. When I tried to change the start date, I got undefined behavior (In some cases my browser freezed completely.). The solution was to copy the start date and manipulate the copy instead of the start date directly.. This is what I ended up with:
datePicker.addShowRangeHandler(new ShowRangeHandler<java.util.Date>()
{
@Override
public void onShowRange(ShowRangeEvent<Date> event)
{
Date start = event.getStart();
Date temp = CalendarUtil.copyDate(start);
Date end = event.getEnd();
Date today = new Date();
while(temp.before(end))
{
if(temp.after(today) && datePicker.isDateVisible(temp))
{
datePicker.setTransientEnabledOnDates(false,temp);
}
CalendarUtil.addDaysToDate(temp, 1);
}
}
});
This should work in GWT 2.4. Earlier versions are not tested.
精彩评论