OptionalFieldEditor的奇怪行为

时间:2012-08-27 01:24:24

标签: gwt gwt-editors

我使用以下编辑器来支持可空列表:

public class NullableListEditor<T, E extends Editor<T>> extends Composite implements 
IsEditor<OptionalFieldEditor< List<T>, ListEditor<T,E> >> {
  private ListEditor<T, E> list = ListEditor.of(new ListEditorSource());
  private final OptionalFieldEditor<List<T>, ListEditor<T, E> > editor = OptionalFieldEditor.of(list);
…
}
public class NullableAListEditor  extends NullableListEditor<A, AEditor> {..}
public class NullableBListEditor  extends NullableListEditor<B, BEditor> {..}

如果我创建了两个实例,比如首先创建NullableAListEditor然后再创建NullableBListEditor,NullableAListEditor将正常工作,但NullableBListEditor将失败,抱怨BEditor无法转换为AEditor。 (如果我创建B然后A,A将因类似原因而失败。) 我调试了它,它似乎是AbstractEditorDelegate.java中的一个问题: http://code.google.com/p/google-web-toolkit/source/browse/releases/2.4/user/src/com/google/gwt/editor/client/impl/AbstractEditorDelegate.java?r=10474 在第75行,对于NullableBListEditor,createComposedDelegate()返回的对象类型与NullableAListEditor的对象类型相同。在创建第一个编辑器(NullableAListEditor)之后,似乎该类型不会再改变,但我无法弄清楚原因。

详细错误:

java.lang.ClassCastException: ..editor.B.BEditor cannot be cast to
...editor.A.AEditor
at ..editor.A.AEditor_SimpleBeanEditorDelegate.setEditor(AEditor_SimpleBeanEditorDelegate.java:6)
    at com.google.gwt.editor.client.impl.AbstractEditorDelegate.initialize(AbstractEditorDelegate.java:200)
    at com.google.gwt.editor.client.impl.AbstractEditorDelegate.addSubDelegate(AbstractEditorDelegate.java:156)
    at com.google.gwt.editor.client.impl.AbstractEditorDelegate$Chain.attach(AbstractEditorDelegate.java:78)
    at com.google.gwt.editor.client.adapters.ListEditorWrapper.attach(ListEditorWrapper.java:95)
    at com.google.gwt.editor.client.adapters.ListEditor.setValue(ListEditor.java:164)
    at com.google.gwt.editor.client.adapters.ListEditor.setValue(ListEditor.java:1)
    at com.google.gwt.editor.client.impl.Refresher.visit(Refresher.java:40)
    at com.google.gwt.editor.client.impl.Initializer.visit(Initializer.java:49)
    at com.google.gwt.editor.client.impl.AbstractEditorContext.traverse(AbstractEditorContext.java:128)
    at com.google.gwt.editor.client.impl.AbstractEditorDelegate$Chain.traverse(AbstractEditorDelegate.java:100)
    at com.google.gwt.editor.client.impl.AbstractEditorDelegate$Chain.attach(AbstractEditorDelegate.java:83)
    at com.google.gwt.editor.client.adapters.OptionalFieldEditor.setValue(OptionalFieldEditor.java:113)
    at com.google.gwt.editor.client.impl.Refresher.visit(Refresher.java:40)
    at com.google.gwt.editor.client.impl.Initializer.visit(Initializer.java:49)
    at com.google.gwt.editor.client.impl.AbstractEditorContext.traverse(AbstractEditorContext.java:128)

我做错了吗?

非常感谢, -Jeff

1 个答案:

答案 0 :(得分:0)

只是跑进issue 6016。它在GWT 2.5.0-rc1中修复。