DateField only with java.util.Date?

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 :

  1. 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.

  2. 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

https://vaadin.com/directory#addon/javaee-application-addon-for-vaadin:vaadin=7.

At this link you can find any Converter than you need, and a simple base for you ExtendedConverterFactory

https://github.com/thomasletsch/javaee-addon/tree/master/src/main/java/org/vaadin/addons/javaee/fields/converter

Remenber to set in your VaadinSession your custom factory!!

@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.

I suppose that you need create a new RangeValidator for DateField, and add it manualy on fields.