Book Image

Vaadin 7 Cookbook

Book Image

Vaadin 7 Cookbook

Overview of this book

Table of Contents (19 chapters)
Vaadin 7 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Filtering items using ComboBox


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.

How to do it...

In this recipe, we will update the list of cities according to the country selected:

  1. Create a Vaadin project with a main UI class called Demo.

    public class Demo extends UI {…}
  2. We start with the Country class. In this class, we need two attributes, namely, name and container 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...