Search code examples
gwtuibinder

How to get a MultipleSelect ListBox with GWT using UiBinder


I'm working on an app developped with GWT using UiBinder. In one view, I have a ListBox that needs to allow multiselection.

The app is currently using the method setMultipleSelect(boolean isMultipleSelect) to enable multi-selection on the ListBox. That method is now deprecated and it is advised to use the constructor ListBox(boolean isMultipleSelect).

The problem is that I'm not constructing that ListBox, is it done when binding (I think, I'm not really sure how it's all working).

My code is like that :

interface ViewUiBinder extends UiBinder<Widget, View> {}

private static ViewUiBinder uiBinder = GWT.create(ViewUiBinder.class);

private Widget widget;
@UiField
ListBox listBox;

@Inject
public View() {
  widget = uiBinder.createAndBindUi(this);
  listBox.setMultipleSelected(true);
}

Does anyone know how to init the ListBox with the multiselection constructor constructor and make it work ?

Thanks,

Mathieu


Solution

  • I would use the provided = true annotation paramenter for UiField and initialize the field. If you don't want to initialize the listbox with the field, but in the View constructor, set the statement before uiBinder.createAndBinUi(this);

    @UiField(provided = true)
    ListBox listBox = new ListBox(true);