gpt4 book ai didi

GWT ValueListBox、渲染器和 ProvidesKey

转载 作者:行者123 更新时间:2023-12-02 15:17:17 25 4
gpt4 key购买 nike

如何使用特定的对象列表在编辑器中实现 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();
}

});
...

乡村类

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

但是,在 GWT 编译期间,我收到此错误:

Type mismatch: cannot convert from String to Country

最佳答案

问题是您正在尝试使用Country编辑器编辑address.countryCode(查看路径注释)。要实现此目的,您应该将路径更改为 address.country 并在 editorDriver.flash() 之后分配 address.countryCode 。像这样的东西:

Address address = editorDriver.flush();
address.setCountryCode(address.getCountry().getCountryCode());

为了支持这一点,Address 类应该将 Country 对象作为属性。

您可能假设 ValueListBox 将像经典的 select 一样工作,其中键被分配给属性。这里整个对象被分配。因此,在您的情况下 Country 对象不能分配给 address.countryCode ,反之亦然。

顺便说一句。您可以更正渲染器(如下面的代码)并在渲染器和 key 提供程序中将 null 对象作为参数处理。

new Renderer<Country>() {
...
@Override
public void render(Country object, Appendable appendable)
throws IOException {
appendable.append(render(object));
}
...
}

关于GWT ValueListBox、渲染器和 ProvidesKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10116154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com