Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 3 weeks ago
What would be the best practice to use ComboBox for data gathered from an o
Have a comboBox that shows list of objects I get from outside rest service in JSON. Currently made it this way, getting first 1000 objects and if there is no suitable one I attached a New Item handler that makes a new request with entered text as a query. So I am wondering is there another better way.
Here is some of my code:
private VerticalLayout addLayout () {
Collection initialCollection = service.getResults();
ComboBox university = new ComboBox("University", initialCollection );
addComponent(university);
university.setNewItemHandler(newItemCaption -> {
initialCollection.removeAllItems();
bindItemsToComboBox(university, service.getResults(newItemCaption) );
});
return layout;
}
public static void bindItemsToComboBox(ComboBox comboBox, Collection items){
for (Object o : items){
comboBox.addItem(o);
comboBox.setItemCaption(o,o.toString());
}
}
Last updated on
You cannot reply to this thread.