title: Vaadin7 dynamically populate combobox from Rest API
body: <p>I would like to dynamically populate a combobox from Vaadin7 using a rest API. The API returns a lot of values if not filtered. </p>
  
  <p>This is the basic idea I have. I know that the version of Vaadin contains better ways to bind data but I need to use this is a new-old legacy system. </p>
  
  <p>My main problem is that the event does not fire when typing new values and also I am not sure how to get the current value in the combobox so I can send it as a filter to the API</p>
  
  <p>Here is the code </p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringUI
  public class MainView extends UI {
  
    @Autowired
    private NameService nameService;
  
    private ComboBox comboBox;
  
    @Override
    protected void init(VaadinRequest request) {
      VerticalLayout verticalLayout = new VerticalLayout();
  
      comboBox = new ComboBox();
      comboBox.setContainerDataSource(getDataSource());
      comboBox.setItemCaptionMode(ItemCaptionMode.PROPERTY);
      comboBox.setItemCaptionPropertyId("name");
      comboBox.setImmediate(true);
  
      comboBox.addValueChangeListener(event -&gt; {
            // When I manually enter a property I want to go to the server
            // Rest API and get a new List of names
            String filter = event.getProperty().toString();
            comboBox.setContainerDataSource(getDataSourceWithFilter(filter));
          }
      );
  
      verticalLayout.addComponent(comboBox);
      setContent(verticalLayout);
    }
  
    // Get 20 names with a filter
    private BeanContainer&lt;String, Name&gt; getDataSourceWithFilter(String filter) {
      BeanContainer&lt;String, Name&gt; container = new BeanContainer&lt;&gt;(Name.class);
  
      container.setBeanIdResolver(Name::getId);
      // this list comes from a webservice API
      List&lt;Name&gt; names = nameService.fetch(filter, 0, 20).collect(Collectors.toList());
      container.addAll(names);
  
      return container;
    }
  
    // Get 20 (default) names without filtering
    private BeanContainer&lt;String, Name&gt; getDataSource() {
      return getDataSourceWithFilter("");
    }
  }
  </code></pre>