GWT Editor use IsEditor<LeafValueEditor<Date>> to populate Long field

1.8k views Asked by At

I just got the hang of using the Editor framework and am porting over all my forms to use it. I'm running into some trouble on my Event form. I have 5 different time fields - for each field I use a DateBox to allow the user to select the time.

In my old Activity i converted the values of these fields to Long times, populated my proxy object and persisted it.

I want to do the same thing using the Editor framework. Is there anyway I can use an Editor with a DateBox to populate a Long field in my domain object. I'm sure there's got to be a way to do this I'm just having trouble figuring it out.

If this is not the case and I just can't do this for now, does anybody know a good solution for how to do this?

1

There are 1 answers

0
Thomas Broyer On BEST ANSWER

You have to wrap the DateBox in an Editor<Long>. Something like:

@Editor.Ignore
@UiField
DateBox dateField;

LeafValueEditor<Long> longField = new LeafValueEditor<Long>() {
    @Override
    public Long getValue() {
        Date date = dateField.getValue();
        return date == null ? null : date.getTime();
    }
    @Override
    public void setValue(Long value) {
        Date date = value == null ? null : new Date(value.longValue());
        dateField.setValue(date);
    }
}