GWT编辑器使用Map绑定到POJO

时间:2012-04-14 13:43:19

标签: gwt

我是GWT的新手并试图加快编辑框架的速度,并且偶然发现我认为这是一个容易的障碍。

我有以下Model对象:

public class Person implements Serializable {
    protected String name;  
    protected Map<AddressID, Address> addresses;
}
public class Address {
    protected String street;
    protected String city;
}
public interface AddressID { }

我正在尝试使用带有地址子编辑器的编辑器,以便他们看到页面底部的地址列表。这是我的编辑:

public class PersonEditor extends Composite implements Editor<Person> {

    private static PersonEditorUiBinder uiBinder = GWT.create(PersonEditorUiBinder.class);
    interface PersonEditorUiBinder extends UiBinder<Widget, PersonEditor> {}

    @UiField
    TextBox name;
    @UiField
    AddressEditor addresses;

    @Inject
    public ModelConfigEditor() {
        initWidget(uiBinder.createAndBindUi(this));
    }
}
public class AddressEditor extends Composite implements LeafValueEditor<Map<AddressID, Address>> {
    private Map<AddressID, Address> addresses = new HashMap<AddressID, Address>();
    private VerticalPanel mainPanel;

    public AddressEditor() {
        setMainPanel();
        setupDialogBox();
        this.initWidget(mainPanel);
    }

    @Override
    public void setValue(Map<AddressID, Address> value) {
        this.addresses = value;

    }

    @Override
    public Map<AddressID, Address> getValue() {
        return addresses;
    }
}

最后,这是我的ui.xml片段,我想要显示地址:

<g:HTMLPanel>
    <table>
        <tr>
            <g:VerticalPanel ui:field="settingsPanel">
                <g:HTMLPanel width="100%">
                    <q:FieldConfigImplEditor ui:field="addresses"
                        styleName="{style.panelInline}" />
                </g:HTMLPanel>
            </g:VerticalPanel>
        </tr>
    </table>
</g:HTMLPanel>

页面呈现,我可以编辑Person对象中的字段,但地址不存在。通过调试器运行我看到我的setVaule(Map值)被称为一个值填充了Address对象。如何让地址显示在屏幕上?

0 个答案:

没有答案