GWT 列表编辑器绑定

发布于 12-11 05:55 字数 2448 浏览 1 评论 0 原文

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

public interface PersonFriend {
    String getName();
}

我正在尝试为 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);  
    }
}

当我将 Person 对象绑定到 PersonViewEditor 时,friendsEditor 永远不会绑定到某人的好友列表。看起来 PersonFriendsViewEditor 应该实现一些神奇的接口以允许 GWT 与其交互,但我找不到任何相关文档。 GWT 中有 dynatablerf 示例,但它们显式绑定列表编辑器,我很好奇将其绑定为“外部”对象的一部分,因此我只需将 Person 绑定到 PersonViewEditor 它拥有所有数据/设置所有小部件。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东风软 2024-12-18 05:55:25

PersonFriendsViewEditor 应该实现 IsEditor> - 解决了问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文