jmizv
jmizv

Reputation: 1312

Get all values available in a Combobox in Vaadin

There are several comboboxes in my code which I fill with values via

  List<String> items = ...
  combobox.setItems(items);

but I don't really know how to get all these items out of it. In the previous case, of course, it is easy because the items object still exists. But in more complex cases, e.g. debugging, I'd like to have something like

  List<String> items = combobox.getItems();

but I couldn't find any suggestion how to do it. Even official Vaadin documentation doesn't say a word about it: https://vaadin.com/components/vaadin-combo-box/java-examples

I know there might be some more complex cases when using comboBox.setDataProvider(service::fetch, service::count);.

Upvotes: 3

Views: 1773

Answers (1)

Tatu Lund
Tatu Lund

Reputation: 10623

If you use combobox.setItems(items); then ComboBox will automatically create a ListDataProvider out of those items, which means that you could the following

ListDataProvider dataProvider = (ListDataProvider) comboBox.getDataProvider();
allItems = dataProvider.getItems();

Upvotes: 4

Related Questions