Implement NullableSetEditor by wrapping a NullalbleListEditor

℡╲_俬逩灬. 提交于 2019-12-13 07:34:02

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!