I'm using a DateField in Vaadin with a Converter to enable the usage of LocalDateTime of java.time Package.
When I'm using the Converter and limit the DateField by setRangeEnd() the DateField always shows an UserError with the message 'Date is out of allowed Range'. Without using the Converter it works fine.
My Converter:
public class LocalDateTimeToDateConverter implements Converter<Date,LocalDateTime> {
private static final long serialVersionUID = -4900262260743116965L;
@Override
public LocalDateTime convertToModel(Date value, Class<? extends LocalDateTime> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value != null) {
return value.toInstant().atZone(ZoneOffset.systemDefault()).toLocalDate().atStartOfDay();
}
return null;
}
@Override
public Date convertToPresentation(LocalDateTime value, Class<? extends Date> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value != null) {
return Date.from(value.atZone(ZoneOffset.systemDefault()).toInstant());
}
return null;
}
@Override
public Class<LocalDateTime> getModelType() {
return LocalDateTime.class;
}
@Override
public Class<Date> getPresentationType() {
return Date.class;
}
}
MyView where is use the DateField:
dateField = new DateField();
dateField.setDateFormat("yyyy-MM-dd");
dateField.setRangeStart(null);
dateField.setRangeEnd(Date.from(lastAvailableDataDate.atZone(ZoneId.systemDefault()).toInstant()));
dateField.setConverter(new LocalDateTimeToDateConverter());
Anyone knows how i can set the range while using the converter?