When we
need to filter data in the fields, we can use ComboBox
. In this component, items are filtered based on the user input and loaded dynamically (lazy loading) from the server. In this recipe, we will see how to use this component. In addition, we create two bound fields. The first one will be dynamically updated according to the second field.
In this recipe, we will update the list of cities according to the country selected:
Create a Vaadin project with a main UI class called
Demo
.public class Demo extends UI {…}
We start with the
Country
class. In this class, we need two attributes, namely,name
andcontainer
of cities. The property name will be used for a caption of countries in the Country combobox. The container will contain the name of cities related to this country.public class Country { private String name; private BeanItemContainer<String> citiesContainer = new BeanItemContainer<>(String.class); public...