Hello,
I’m trying make a Datefield that works with a long instead of a Date object (I receive a POJO from somewhere else that I want to fill in using a form, and this POJO uses longs instead of Dates).
I made this little DateField wrapper based on FieldWrapper:
public class TimestampField extends FieldWrapper<Long> {
private DateField dateField;
public TimestampField(String caption) {
super(new DateField(), Long.class);
this.dateField = (DateField)getWrappedField();
setCaption(caption);
setCompositionRoot(this.dateField);
}
@Override
protected Object format(Long value) {
return new Date(value);
}
@Override
protected Long parse(Object formattedValue) throws ConversionException {
return ((Date)formattedValue).getTime();
}
}
However, this gives some problems because a DateField only accepts ‘Date’ properties:
Caused by: java.lang.IllegalArgumentException: DateField only supports Date properties
at com.vaadin.ui.DateField.setPropertyDataSource(DateField.java:548)
at com.vaadin.ui.FieldWrapper.<init>(FieldWrapper.java:117)
at com.datadobi.dobiminer.ui.vaadin.chargeback.config.connectors.components.TimestampField.<init>(TimestampField.java:17)
... more than 36 more
It seems right that the DateField complains about the property, since the PropertyConvertor used by the FieldWrapper probably says it has type ‘Long’, but it also seems to be an ‘unfair’ limitation of the FieldWrapper, since you should be able to convert pigs to elephants, as long as your wrapped field is able to display elephants.
Am I on a dead end here and try somerthing else, or is there a way to fix my problem using FieldWrapper?
Happy Newyear!