GWT编辑器使用IsEditor <leafvalueeditor <date>&gt;填充Long字段</leafvalueeditor <date>

时间:2012-01-11 06:33:44

标签: java gwt gwt-editors

我只是忙于使用Editor framework并移植我的所有表单来使用它。我在Event表单上遇到了麻烦。我有5个不同的time fields - 对于每个字段,我使用DateBox来允许用户选择时间。

在我原来的Activity我将这些字段的值转换为Long次,填充了我的proxy object并保留了它。

我想使用Editor framework做同样的事情。无论如何,我可以使用EditorDateBox填充我的域对象中的Long字段。我确信必须有办法做到这一点我只是难以搞清楚。

如果情况并非如此,我现在暂时无法做到这一点,是否有人知道如何做到这一点的好方法?

1 个答案:

答案 0 :(得分:10)

您必须将DateBox包裹在Editor<Long>中。类似的东西:

@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);
    }
}