GWT ValueListBox, Renderer and ProvidesKey

3
如何在特定对象列表内使用GWT ValueListBox实现编辑器,以下是我的代码:
...
@UiField(provided = true)
@Path("address.countryCode")
ValueListBox<Country> countries = new ValueListBox<Country>(
        new Renderer<Country>() {

            @Override
            public String render(Country object) {
                return object.getCountryName();
            }

            @Override
            public void render(Country object, Appendable appendable)
                    throws IOException {
                render(object);
            }
        },          
        new ProvidesKey<Country>() {
            @Override
            public Object getKey(Country item) {
                return item.getCountryCode();
            }

        });
...

Country 类

public class Country  {
    private String countryName;
    private String countryCode;
}

但是,在进行GWT编译期间,我遇到了以下错误:
Type mismatch: cannot convert from String to Country

你能附上你正在为其制作编辑器的类吗?其中包含国家字段。 - cardamo
1个回答

2
问题在于您正在尝试使用“Country”的编辑器编辑“address.countryCode”(查看路径注释)。 要使此工作正常,您应该将路径更改为“address.country”,并在“editorDriver.flash()”之后对“address.countryCode”进行赋值。类似以下内容:
Address address = editorDriver.flush();
address.setCountryCode(address.getCountry().getCountryCode());

为了支持这一点,地址类应该将国家对象作为属性。 你可能认为ValueListBox像经典的

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接