title: How must one use a ListEditor as a child of another Editor?
body: <p>I am using GWT 2.5.0</p>
  
  <p>My intent was to create an editor hierarchy which binds to a <code>ParentBean</code> object. The <code>ParentBean</code> contains a <code>List&lt;Group&gt;</code>, and the <code>Group</code> bean has a <code>List&lt;ChildBean&gt;</code> and <code>List&lt;Group&gt;</code>. From the Editor tutorials I have found, it seemed simple enough to create an editor which contains a ListEditor as one of its sub-editors. But the parent editor never seems to properly initialize the sub ListEditor.</p>
  
  <p>Here is an explanation of how I attempted to do this.</p>
  
  <p>From the code below, I created a <code>ParentBeanEditor</code> which is composed of one other editor, <code>GroupListEditor</code>. <br>
  The <code>GroupListEditor</code> implements <code>IsEditor&lt;ListEditor&lt;Group, GroupEditor&gt;&gt;</code>.<br>
  Then, the <code>GroupEditor</code> contains a <code>GroupListEditor</code> subeditor and a <code>ChildBeanEditor</code>.</p>
  
  <p>I initialized the <code>ParentBeanEditor</code> with a <code>ParentBean</code> which contained a list of <code>Group</code> objects, but no <code>GroupEditor</code> was ever constructed for any of the <code>Group</code> objects. <br>I put break points in the <code>EditorSource&lt;GroupEditor&gt;.create(int)</code> method to verify that <code>GroupEditor</code>s were being created for each <code>Group</code> in the <code>ParentBean</code>, but the break point was never hit (the ListEditor was not constructing editors).</p>
  
  <p>I expected that the <code>GroupListEditor</code> would be initialized since it was a subeditor of <code>ParentBeanEditor</code>. Neither the list nor the editor chain was set in the <code>GroupListEditor</code>. I tried to set the list of the <code>GroupListEditor</code> subeditor directly in <code>ParentBeanEditor</code> by having it extend <code>ValueAwareEditor&lt;ParentBean&gt;</code>. Doing this, the break point I mentioned above was hit, and the <code>GroupListEditor</code> tried to attach a <code>GroupEditor</code> to the editor chain. But the editor chain was never set, and a NPE is thrown in <code>ListEditorWrapper</code> line 95.</p>
  
  <h1>Example</h1>
  
  <p>Here is the example where the <code>GroupListEditor</code> is not initializing as expected. The <code>EditorChain</code> is never set, and this results in a NPE being thrown in <code>ListEditorWrapper</code> line 95.</p>
  
  <h2>Data Model</h2>
  
  <pre><code>public interface ParentBean {
      ...
      List&lt;Group&gt; getGroups();
  }
  
  public interface Group {
      ...
      List&lt;ChildBean&gt; getChildBeans();
      List&lt;Group&gt; getGroups();
  }
  
  public interface ChildBean {
      // ChildType is an enum
      ChildType getChildType();
  }
  </code></pre>
  
  <h2>Editors</h2>
  
  <p>The ParentBean Editor</p>
  
  <pre><code>public class ParentBeanEditor extends Composite implements ValueAwareEditor&lt;ParentBean&gt; {
  
      interface ParentBeanEditorUiBinder extends UiBinder&lt;Widget, ParentBeanEditor&gt; {
      }
  
      private static ParentBeanEditorUiBinder BINDER = GWT.create(ParentBeanEditorUiBinder.class);
  
      @Path("groups")
      @UiField
      GroupListEditor groupsEditor;
  
      public ParentBeanEditor() {
          initWidget(BINDER.createAndBindUi(this));
      }
  
      @Override
      public void setDelegate(EditorDelegate&lt;ParentBean&gt; delegate) {}
  
      @Override
      public void flush() {}
  
      @Override
      public void onPropertyChange(String... paths) {}
  
      @Override
      public void setValue(ParentBean value) {
  
          groupsEditor.asEditor().setValue(value.getGroups());
      }
  }
  </code></pre>
  
  <p>GroupListEditor</p>
  
  <pre><code>public class GroupListEditor extends Composite implements IsEditor&lt;ListEditor&lt;Group, GroupEditor&gt;&gt;{
  
      interface GroupListEditorUiBinder extends UiBinder&lt;VerticalLayoutContainer, TemplateGroupListEditor&gt; {
      }
  
      private static GroupListEditorUiBinder BINDER = GWT.create(GroupListEditorUiBinder.class);
  
      private class GroupEditorSource extends EditorSource&lt;GroupEditor&gt; {
  
          private final GroupListEditor GroupListEditor;
  
          public GroupEditorSource(GroupListEditor GroupListEditor) {
              this.GroupListEditor = GroupListEditor;
          }
  
          @Override
          public GroupEditor create(int index) {
              GroupEditor subEditor = new GroupEditor();
              GroupListEditor.getGroupsContainer().insert(subEditor, index);
              return subEditor;
          }
  
          @Override
          public void dispose(GroupEditor subEditor){
              subEditor.removeFromParent();
          }
  
          @Override
          public void setIndex(GroupEditor editor, int index){
              GroupListEditor.getGroupsContainer().insert(editor, index);
          }
  
      }
  
      private final ListEditor&lt;Group, GroupEditor&gt; editor = ListEditor.of(new GroupEditorSource(this));
  
      @UiField
      VerticalLayoutContainer groupsContainer;
  
      public GroupListEditor() {
         initWidget(BINDER.createAndBindUi(this));
      }
  
      public InsertResizeContainer getGroupsContainer() {
          return groupsContainer;
      }
  
      @Override
      public ListEditor&lt;Group, GroupEditor&gt; asEditor() {
          return editor;
      }
  }
  </code></pre>
  
  <p>GroupEditor</p>
  
  <pre><code>public class GroupEditor extends Composite implements ValueAwareEditor&lt;Group&gt; {
  
      interface GroupEditorUiBinder extends UiBinder&lt;Widget, GroupEditor&gt; {}
  
      private static GroupEditorUiBinder BINDER = GWT.create(GroupEditorUiBinder.class);
  
      @Ignore
      @UiField
      FieldSet groupField;
  
      @UiField
      @Path("childBeans")
      ChildBeanListEditor childBeansEditor;
  
      @UiField
      @Path("groups")
      GroupListEditor groupsEditor;
  
      public GroupEditor() {
          initWidget(BINDER.createAndBindUi(this));
      }
  
      @Override
      public void setDelegate(EditorDelegate&lt;Group&gt; delegate) {}
  
      @Override
      public void flush() { }
  
      @Override
      public void onPropertyChange(String... paths) {}
  
      @Override
      public void setValue(Group value) {
          // When the value is set, update the FieldSet header text
          groupField.setHeadingText(value.getLabel());
          groupsEditor.asEditor().setValue(value.getGroups());
          childBeansEditor.asEditor().setValue(value.getChildBeans());
      }
  }
  </code></pre>
  
  <p>The <code>ChildBeanListEditor</code> will be using the polymorphic editor methodology mention <a href="https://stackoverflow.com/questions/7043760/using-gwt-editors-with-a-complex-usecase" title="here">here</a>. Meaning that a specific leafeditor is attached to the editor chain based off the value of the <code>ChildBean.getType()</code> enum. However, I am not showing that code since I am unable to get the <code>GroupListEditor</code> to properly initialize.</p>