GWT ValueListBox, Renderer, and ProvidesKey

How to implement GWT ValueListBox inside the 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();
            }

        });
...

Country Class

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

But during compilation of GWT I get this error:

Type mismatch: cannot convert from String to Country
+3
source share
1 answer

The problem is that you are trying to edit address.countryCode(looking at the path annotation) using the editor for Country. To do this, you must change the path to address.countryand complete the assignment address.countryCodeafter editorDriver.flash(). Sort of:

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

To support this, the Address class must have a Country object as a property.

, , ValueListBox select, . . Country address.countryCode .

Btw. (, ) null Renderer Key.

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

All Articles