我刚刚掌握了使用 Editor framework
的窍门,并且正在移植我所有的表单来使用它。我在处理 Event
表单时遇到了一些问题。我有 5 个不同的 time fields
- 对于每个字段,我都使用 DateBox
来允许用户选择时间。
在我的旧Activity
中,我将这些字段的值转换为Long
时间,填充我的代理对象
并保存它。
我想使用 Editor framework
做同样的事情。无论如何我可以使用带有 DateBox
的 Editor
来填充我的域对象中的 Long
字段。我确信一定有办法做到这一点,我只是无法弄清楚。
如果不是这种情况,我现在不能这样做,有没有人知道如何做到这一点的好的解决方案?
最佳答案
你必须包装 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);
}
}
关于java - GWT 编辑器使用 IsEditor<LeafValueEditor<Date>> 填充 Long 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8815118/