tj-*_*ess 11 java gwt gwt-editors
我遵循类层次结构.
class A {
String id;
@NotEmpty(message="Title can't be empty")
String title;
String description;
String comments;
}
class B extends A {
String manufacturer;
}
class C extends A {
long size;
}
Run Code Online (Sandbox Code Playgroud)
现在我想要一个重用A编辑器的编辑器,同时也适用于B和C的值.所以我继续跟进:
class EditorA extends Composite implements Editor<A> {
@uiField
TextBox id;
@uiField
TextBox title;
@uiField
TextBox description;
// .. constructor etc
}
class EditorB extends Composite implements Editor<B> {
@Path(“”)
@UiField
EditorA editorA;
@UiField
TextBox manufacturer;
public interface Driver extends SimpleBeanEditorDriver<B, EditorB>{}
// .. initialization
}
class EditorC extends Composite implements Editor<C> {
@Path(“”)
@UiField
EditorA editorA;
@UiField
LongBox size;
public interface Driver extends SimpleBeanEditorDriver<C, EditorC>{}
// .. initialization
}
Run Code Online (Sandbox Code Playgroud)
然后我根据正在编辑的实际类型选择编辑器.驱动程序正确刷新对象.但是当我显示约束违规时,每个违规都会在发送到小部件之前重复,例如
"标题不能为空""标题不能为空"
更糟糕的是,如果我在一个表单中包含多个这样的小部件(带有@Path("")注释),则违规行为会不断增加.所以在下面的设置中,设置了3个违规.
class EditorAFooter extends Composite implements Editor<A> {
@UiField
TextBox comments;
}
class EditorB extends Composite implements Editor<B> {
@Path(“”)
@UiField
EditorA editorA;
@UiField
TextBox manufacturer;
@Path(“”)
@UiField
EditorAFooter editorAFooter;
public interface Driver extends SimpleBeanEditorDriver<B, EditorB>{}
// .. initialization
}
Run Code Online (Sandbox Code Playgroud)
解决方法不是在EditorB中使用EditorA,而是复制EditorA的所有小部件并粘贴到EditorB.ui.xml中,然后只设置单个违规(如预期的那样).然而,这是很多代码重复,因为EditorA在现实中非常复杂.
这种编辑器设置有什么问题?我基本上遵循这里提到的指导原则:http://www.gwtproject.org/doc/latest/DevGuideUiEditors.html#Very_large_objects
======更新=======
我进一步调试了它(还没有成功)在SimpleViolation.java中,下面的代码能够为1个属性找到3个匹配的委托:
public static void pushViolations(Iterable<SimpleViolation> violations,
EditorDriver<?> driver, KeyMethod keyMethod) {
if (violations == null) {
return;
}
DelegateMap delegateMap = DelegateMap.of(driver, keyMethod);
// For each violation
for (SimpleViolation error : violations) {
Object key = error.getKey();
List<AbstractEditorDelegate<?, ?>> delegateList = delegateMap.get(key);
Run Code Online (Sandbox Code Playgroud)
上面的delegateList有2或3个编辑器,具体取决于我的配置.可能的原因是因为subType可以访问所有superType属性,因此可以将子类型编辑器驱动程序视为该属性的委托.SuperType的编辑器本身就是一个委托.由于每个人都实现了编辑器,因此每个人都有责 对于涉及的每个编辑器,它会将违规推送到同一个显示违规多次的文本框.
这是预期的吗?如果是,如何正确使用编辑器框架的多态类型并只显示一次ConstraintViolation?