"vaadin converter for java.sql.timestamp" Code Answer

3

i recommend this way:

popupdatefield pdf = new popupdatefield();
timestamp ts = new timestamp(system.currenttimemillis());
objectproperty<timestamp> prop = new objectproperty<timestamp>(ts);
pdf.setpropertydatasource(prop);
pdf.setconverter(myconverter.instance);

with this converter:

public class myconverter implements converter<date, timestamp> {

    private static final long serialversionuid = 1l;
    public static final myconverter instance = new myconverter();

    @override
    public timestamp converttomodel(date value,
            class<? extends timestamp> targettype, locale locale)
            throws conversionexception {
        return value == null ? null : new timestamp(value.gettime());
    }

    @override
    public date converttopresentation(timestamp value,
            class<? extends date> targettype, locale locale)
            throws conversionexception {
        return new date(value.gettime());
    }

    @override
    public class<timestamp> getmodeltype() {
        return timestamp.class;
    }

    @override
    public class<date> getpresentationtype() {
        return date.class;
    }

    private object readresolve() {
        return instance; // preserves singleton property
    }

}
By j3ff on January 4 2022

Answers related to “vaadin converter for java.sql.timestamp”

Only authorized users can answer the Search term. Please sign in first, or register a free account.