Java 用于多态类型的GWT编辑器框架

Java 用于多态类型的GWT编辑器框架,java,gwt,gwt-editors,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; } 现在我想要一个编辑器,它可以重用A的编辑器,并且可以很好地处

我有以下的类层次结构

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;
}
现在我想要一个编辑器,它可以重用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
}
类EditorA扩展复合实现编辑器

=======更新======

我进一步调试了它(还没有成功) 在SimpleVolation.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);
公共静态违规(可容忍违规、,
EditorDriver驱动程序,KeyMethod KeyMethod){
如果(冲突==null){
返回;
}
DelegateMap DelegateMap=DelegateMap.of(驱动程序,键方法);
//每一次违规
对于(SimpleVolation错误:违规){
Object key=error.getKey();

ListI不久前也遇到过类似的情况,有人给了我一个很好的答案。答案是:类中是否有EditorWidgets的getter。这可能是导致问题的原因。您可以尝试在getter方法或字段上使用@Editor.Ignore。这将告诉编辑器框架忽略此编辑器。@Slagmandrew是否显示了ConstraintViolations在您的代码中?它们是否正确显示(即,没有如我上面所解释的那样出现x2或x3次)?@slugmandrew我确实尝试了您提到的示例。ConstraintViolations仍会发布多次(即使驱动程序只生成一次违规)。如果您使用该示例来发布违规行为,请告诉我。@ChrisHinshaw没有getter,编辑器字段是默认范围,并用@UiField注释。我不太明白您要将@Ignore放在哪里
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);