gwtgwt2gwt-editors

Simple GWT Editor Example


I'm finding anything other than copying and pasting existing GWT Editor examples to be frustrating. Here's an attempt to create a minimal Editor, without success.

public class ContactEditor extends Composite implements Editor<Contact> {

    interface Binder extends UiBinder<Widget, ContactEditor> {}

    interface ContactEditorDriver extends
        SimpleBeanEditorDriver<Contact, ContactEditor> {}
    private final ContactEditorDriver editorDriver;

    @UiField TextBox salutation;

    public ContactEditor(Contact contact) {
        editorDriver = GWT.create(ContactEditorDriver.class);
        editorDriver.initialize(this); 
        editorDriver.edit(contact);

        initWidget(GWT.<Binder> create(Binder.class).createAndBindUi(this));
    }
}

When this is instantiated with

ContactEditor contactEditor = new ContactEditor(new Contact());

I get an UmbrellaException that contains

Caused by: java.lang.NullPointerException: null
    at ...ContactEditor_SimpleBeanEditorDelegate.attachSubEditors(ContactEditor_SimpleBeanEditorDelegate.java:12)
    at com.google.gwt.editor.client.impl.AbstractEditorDelegate.initialize(AbstractEditorDelegate.java:264)
    at com.google.gwt.editor.client.impl.SimpleBeanEditorDelegate.initialize(SimpleBeanEditorDelegate.java:32)
    at com.google.gwt.editor.client.impl.AbstractSimpleBeanEditorDriver.edit(AbstractSimpleBeanEditorDriver.java:45)
    at ...ContactEditor.<init>(ContactEditor.java

What's going on here---SubEditors? The failure seems to be in generated code and is hard for me to debug.

Much thanks.


Solution

  • By the time you initialize the editor driver, the "salutation" subeditor isn't initialized yet (still null).

    Move your createAndBindUi call before the editor init call.