Vaadin 8 ComboBox with CallbackDataProvider

After upgrading to Vaadin 8, the AutoComplete comboboxes that I used with Vaadin 7 no longer work. I expected as much since ComboBox now takes DataProviders and not Containers.

After reading through all the documentation I created a CallbackDataProvider. Each of the required query methods call to backend SOLR to return Persons as filtered by text entered in the ComboBox.

The result? The CallbackDataProvider behaves strangely.

  • If I have one “Sheila” in the backend list and I type “S” (let’s assume that “S” matches nothing else), the dataprovider displays the one result returned from SOLR -“Sheila”.
  • If I then type “Sh”, the dataprovider now increases to TWO and provides two objects of “Sheila” which are identical. Note: the list return from the backend is still a single object, not TWO - that is “Sh” still only matches “Sheila”.
  • This continues for as many times that I TYPE a character into the Combobox.
  • S - > one Sheila in the ComboBox dropdown list
  • Sh → two identicial Sheila the ComboBox dropdown list
  • She → three identicial Sheila the ComboBox dropdown list
  • Shei → ok, you get the idea

I have found no method to remove/clear the items in the dataprovider.

It should be simple, but I am at a loss.

Code Snippet

comboBox = new ComboBox<>();
comboBox.setPlaceholder(“Enter text to find a person”);
comboBox.setDataProvider(new CallbackDataProvider<MyObject, String>(
query → { return presenter.fetchPersons(query.getOffset(),
null).stream(); },
query → { return presenter.getPersonCount(query.getOffset(),

Any suggestions on how to clear the dataprovider or prevent the unnecessary increase in results are welcome.



Things I learned (or re-learned) in the last 12 hours:

  • Sleep is important. Get some.
  • Re-reading the documentation is essential.
  • Walking through ALL the code is also essential.

What Was Missing:

  1. Make sure to add in the method used to identify

comboBox.setDataProvider(new CallbackDataProvider<
, String>( query → { return presenter.fetchPersons(query.getFilter().orElse(null), null).stream(); }, query → { return presenter.getPersonCount(query.getFilter().orElse(null), null); },

  1. Make sure you provide the correct
    of the items returned.

Yep, I goofed. Long story short, my method to return the count of the records was incorrect (I have to add in some items depending on the filter results). If it doesn’t match EXACTLY, the list is messed up.

Hope this helps someone else.