How to implement a GWT ValueListBox inside an Editor with a specific list of objects, my code:
...
@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();
}
});
...
The Country class
public class Country {
private String countryName;
private String countryCode;
}
But, during the GWT compilation I’m getting this error:
Type mismatch: cannot convert from String to Country
The problem is that you are trying to edit the
address.countryCode(looking at the path annotation) with editor forCountry.To make this work, you should change the path to
address.countryand do the assignment of theaddress.countryCodeaftereditorDriver.flash(). Something like:To support this, the Address class should have the Country object as property.
You may have assumed that the ValueListBox will work like classical
selectwhere the key is assigned to the property. Here the whole object is assigned. So in your caseCountryobject can not be assigned toaddress.countryCodeand vice-versa.Btw. you can correct the renderer (like the code below) and take care of
nullobjects as arguments in the Renderer and Key Provider.