gwtgwt-widgetsgwt-editors

GWT ValueListBox Editor


I'm puzzled about how to use GWT's ValueListBox with an Editor. I'm getting this ERROR:

The method setValue(String) in the type TakesValueEditor<String> 
is not applicable for the arguments (List<String>)

Here's the relevant code.

public class MyBean {
    private List<String> dateFormats;
    public List<String> getDateFormats() {
        return dateFormats;
    }
    public void setDateFormats(List<String> dateFormats) {
        this.dateFormats = dateFormats;
    }
}

public interface MyBeanView extends IsWidget, Editor<MyBean> {
    @Path("dateFormats")
    IsEditor<TakesValueEditor<String>> getDateFormatEditor();
}

public class MyBeanViewImpl implements MyBeanView {
    @UiField(provided=true) ValueListBox<String> dateFormats;

    public MyBeanViewImpl() {
        dateFormats = new ValueListBox<String>(PassthroughRenderer.instance(),
                new ProvidesKey<String>() {
                    @Override
                    public Object getKey(String item) {
                        return item;
                    }
        });
        dateFormats.setAcceptableValues(Arrays.asList(new String[] {"YYYY"}));
        // ... binder.createAndBindUi(this);
    }

    @Override
    public IsEditor<TakesValueEditor<String>> getDateFormatEditor() {
        return dateFormats;
    }
}

Here's what's in ui.xml with xmlns:g='urn:import:com.google.gwt.user.client.ui'>

  <g:HTMLPanel>
     Data Formats: <g:ValueListBox ui:field="dateFormats"> </g:ValueListBox>
  </g:HTMLPanel>

I'm surely missing something obvious here. Much thanks.


Solution

  • The problem that you're running into has to do with trying to map the List<String> dateFormats from MyBean onto the ValueListBox<String> dateFormats editor. The datatypes are incompatible, since a ValueListBox<T> doesn't edit a List<T>, but instead a single instance of T chosen from a list provided by setAcceptableValues(). Given the example above, it would make sense for MyBean to have a String getDateFormat() property and rename the editor field to dateFormat.