Combobox itemlist


Can anybody tell me how can I get a list of items in a combobox? (Vaadin 8)


you can get them from the data provider. If you use the default (adding items with setItems()), it should be a ListDataProvider.


Then you’ll need to do whatever the lazy DataProvider does to get its items. It could be, for example, a SQL query. Note that the DataProvider interface doesn’t specify a way of getting all the possible items - in some cases it might not even make sense to do that. That is left up to the implementations; in ListDataProvider for example it’s done with the getItems() method, but that’s not overidden from any interface.



And if i use lazy DataProvider<T, String>?

:frowning: Thx!

The reason for this is that in the general case, the list of items could be extremely large. However, if fetching all the items is not a problem in your case, you can use something like

getDataProvider().fetch(new Query<>()).collect(Collectors.toList())

Of course I do not want to go back to DB again. I thought the object returns in some way.

Many of the Vaadin data components will typically make partial requests to the data provider (e.g. give me the first 40 items), and will make more requests to the back-end as needed. The specific data provider implementation can perform caching if needed and appropriate. This is needed as the data sets (especially for Grid) are often too big to keep in memory in their entirety.

In cases where your data is small and relatively static, it is often more efficient to make a single database query or request to the back-end to load all the data, and use an in-memory data provider such as the implicit ListDataProvider of setItems(…) for the UI. In that case, a query like the one I suggested above is a fast operation.

I have service class. When i set items alldata() in my combobox then it shows all the embedded data from database. how can i just set the name field?