我正在尝试为一个 bean 对象创建一个 GWT 编辑器,它具有另一个对象类型的两个字段,因此我想要这些字段的子编辑器。问题是我对编辑器框架还很陌生,而且我并不真正了解所有这些编辑器接口。请告知最佳解决方案。我的想法如下:使用子编辑器的驱动程序将数据传递给主编辑器驱动程序;或使用某种 CompositeEditor (但我不知道如何处理被覆盖的方法......)。这是一个示例代码:
public class A {
String s1, s2;
Integer i;
Double d;
B ba, bb;
}
public class B {
BigDecimal a, b;
}
//sub-editor
public class BEditor extends Composite implements Editor<B> {
interface BDriver extends BeanEditorDriver<B, BEditor> {
}
//implements HasEditorErrors interface
ValueBoxEditorDecorator<BigDecimal> a, b;
}
//main editor
public class AEditor extends Composite implements Editor<A> {
interface ADriver extends BeanEditorDriver<A, AEditor> {
}
private ADriver driver = GWT.create(ADriver.class);
ValueBoxEditorDecorator<String> s1, s2;
ValueBoxEditorDecorator<Integer> i;
ValueBoxEditorDecorator<Double> d;
BEditor ba, bb;
public AEditor() {
driver.initialize(this);
driver.edit(new A());
}
//called when the editor form is submitted
public void onSubmit() {
driver.clearErrors();
A a = driver.flush();
// A has both B fields = null
// AEditor successfully displays validation errors,
// but BEditors do not display errors, nor does
// ADriver get any errors from BEditor
}
}
}