Does anybody know the best way how to use DateField with class other then java.util.Date? We would like to use our DateTime library class (similar to JodaTime) without rewrapping everything to standard Date.
I created Converter between Date and our DateTime but there are still some issues :
I cannot use DateTime typed ObjectProperty in the constructor, although it’s no problem to set the same property as datasource using setPropertyDataSource. Not critical, just curious.
Looks like the range validator has problems - I am getting error message ‘Date is out of allowed range’ regardless the min/max range settings.
Hi, using a Converter should work, if you have set it up properly.
You are using a RangeValidator, right? If the DateTime type is comparable, it should work. It should be easy to debug it, just check the types and values that are compared in the isValidValue().
You need create a Converter that implements
Converter<String, DateTime> .
Than extends DefaultConverterFactory and override method
protected Converter<String, ?> createStringConverter(Class<?> sourceType)
to use first you converter like this:
if (DateTime.class.isAssignableFrom(sourceType)) {
return new StringToDateTimeConverter();
}
And in the end you need configure you VaadinSession to use your ConverterFactory with method
setConverterFactory(ExtentedConverterFactory)
You can find a simple base for this stuff on a Addon
Javaee
@Marko: you are right, I forgot to replace the default RangeValidator, now it works. Still a bit confusing the error message when calling constructor with property not typed as .
@Francesco: the Converter was ok, the problem was the RangeValidator. The default one is typed as RangeValidator and cannot work with my DateTime class because DateTime is not a Date subclass.