通过包装NullalbleListEditor实现NullableSetEditor [英] Implement NullableSetEditor by wrapping a NullalbleListEditor
问题描述
public class NullableStringListEditor扩展Composite implements IsEditor< OptionalFieldEditor< List< String>,ListEditor< String,StringEditor> >> {...}
现在,我通过包装构建一个NullableStringSetEditor:
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();
一些空的检查...
list.clear();
list.addAll(values);
wrappedEditor.asEditor()。setValue(list); //会从这里调用OptionalFieldEditor的setValue
code $
错误:
java.lang.NullPointerException:com.google.gwt.editor.client.adapters.OptionalFieldEditor.setValue(可选字段编辑器。 java:113)
第113行:chain.attach(value,subEditor);
它似乎像链始终是空的。
我做错了什么?如果 NullableStringSetEditor
是一个 LeafvalueEditor
,然后 wrappedEditor
将被编辑器框架生成器忽略,因此不会被初始化和填充。
您可能希望通过使您的编辑器成为 CompositeEditor
来遵循 OptionaEditor
模式除了是 LeafValueEditor
)
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!
解决方案 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
)
这篇关于通过包装NullalbleListEditor实现NullableSetEditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!