问题
I have a working NullableStringListEditor implementation:
public class NullableStringListEditor extends Composite implements IsEditor<OptionalFieldEditor< List<String>, ListEditor<String, StringEditor> >> {...}
Now, I am building a NullableStringSetEditor by wrapping it:
public class NullableStringSetEditor extends Composite implements ValueAwareEditor<Set<String>>, LeafValueEditor<Set<String>> {
private NullableStringListEditor wrappedEditor = new NullableStringListEditor();
@Override
public void setValue(Set<String> values) {
List<String> list = wrappedEditor.asEditor().getValue();
some null checking...
list.clear();
list.addAll(values);
wrappedEditor.asEditor().setValue(list); // will call setValue of OptionalFieldEditor from here
}
}
Error:
java.lang.NullPointerException: null at com.google.gwt.editor.client.adapters.OptionalFieldEditor.setValue(OptionalFieldEditor.java:113)
line 113: chain.attach(value, subEditor); it seems like chain is always null.
Am I doing something wrong? Thanks!
回答1:
If NullableStringSetEditor
is a LeafvalueEditor
, then wrappedEditor
will be ignored by the Editor framework generator, and thus won't be initialized and populated.
You might want to follow the OptionaEditor
pattern by having your editor be a CompositeEditor
(in addition to being a LeafValueEditor
)
来源:https://stackoverflow.com/questions/12190355/implement-nullableseteditor-by-wrapping-a-nullalblelisteditor