Based on the suggestions I received, here is what I came up with that works on limiting the selectable dates to only the current day and after. This works on GWT 2.1.1
final DateBox dateBox = new DateBox();
dateBox.addValueChangeHandler(new ValueChangeHandler<Date>()
{
@Override
public void onValueChange(final ValueChangeEvent<Date> dateValueChangeEvent)
{
if (dateValueChangeEvent.getValue().before(today()))
{
dateBox.setValue(today(), false);
}
}
});
dateBox.getDatePicker().addShowRangeHandler(new ShowRangeHandler<Date>()
{
@Override
public void onShowRange(final ShowRangeEvent<Date> dateShowRangeEvent)
{
final Date today = today();
Date d = zeroTime(dateShowRangeEvent.getStart());
while (d.before(today))
{
dateBox.getDatePicker().setTransientEnabledOnDates(false, d);
d = nextDay(d);
}
}
});
And for completeness here are the static
helper methods for manipulating the dates:
private static Date today()
{
return zeroTime(new Date());
}
/** this is important to get rid of the time portion, including ms */
private static Date zeroTime(final Date date)
{
return DateTimeFormat.getFormat("yyyyMMdd").parse(DateTimeFormat.getFormat("yyyyMMdd").format(date));
}
private static Date nextDay(final Date date)
{
return zeroTime(new Date(date.getTime() + 24 * 60 * 60 * 1000));
}