GWT List editor binding
Asked Answered
K

1

6
public interface Person {
    String getName();
    void setName(String name);
    List<PersonFriend> getFriends();
}

public interface PersonFriend {
    String getName();
}

I'm trying to implement a view-only editor for Person:

public class PersonViewEditor extends Composite implements Editor<Person> {
    private static PersonViewEditorUiBinder uiBinder = GWT.create(PersonViewEditorUiBinder.class);
    interface PersonViewEditorUiBinder extends UiBinder<Widget, PersonViewEditor> {}

    @UiField Label nameEditor;
    @UiField PersonFriendsViewEditor friendsEditor;

    @UiField FancyAnchor editAnchor;

    public PersonViewEditor(ClientFactory clientFactory) {
        initWidget(uiBinder.createAndBindUi(this));
        editAnchor.setPlace(
                clientFactory.getPlaceHistoryMapper(), 
                clientFactory.getPlaceController(), 
                new EditPersonPlace());
    }
}

public class PersonFriendsViewEditor extends Composite {
    private static PersonFriendsViewEditorUiBinder uiBinder = GWT.create(PersonFriendsViewEditorUiBinder.class);
    interface PersonFriendsViewEditorUiBinder extends UiBinder<Widget, PersonFriendsViewEditor> {}

    interface Driver extends SimpleBeanEditorDriver<List<PersonFriend>, ListEditor<PersonFriend, PersonFriendViewEditor>> {}

    private class PersonFriendViewEditorSource extends EditorSource<PersonFriendViewEditor> {
        @Override
        public PersonFriendViewEditor create(int index) {
            PersonFriendViewEditor friend = new PersonFriendViewEditor();
            containerPanel.insert(friend, index);       
            return friend;
        }       
    }

    @UiField HorizontalPanel containerPanel;

    public PersonFriendsViewEditor() {
        initWidget(uiBinder.createAndBindUi(this));     
        Driver driver = GWT.create(Driver.class);
        ListEditor<PersonFriend, PersonFriendViewEditor> editor = ListEditor.of(new PersonFriendViewEditorSource());
        driver.initialize(editor);  
    }
}

When I bind Person object to PersonViewEditor, friendsEditor is never bound to person's friends list. It looks like PersonFriendsViewEditor should implement some magic interface to allow GWT interact with it, but I can't find any related docs. There's dynatablerf example in GWT, but they bind their list editor explicitly and I'm curious about binding it as a part of "outer" object, so I just bind Person to PersonViewEditor and it has all the data/sets all the widgets.

Any thoughts?

Kwarteng answered 22/10, 2011 at 12:7 Comment(0)
K
4

PersonFriendsViewEditor should implement IsEditor<ListEditor<PersonFriend, PersonFriendViewEditor>> - that resolved the issue.

Kwarteng answered 22/10, 2011 at 12:24 Comment(1)
Also, PersonFriendsViewEditor.Driver is likely to mess things up.Dug

© 2022 - 2024 — McMap. All rights reserved.