title: Vaadin23 ComBox autocomplete and "Attempted to fetch more items from server than allowed in one go"
body: <p>I'm trying to implement my first Vaadin ComboBox with autocomplete feature. This is what I have so far:</p>
  <pre><code>    ComboBox&lt;CompositeEntityResult&gt; companyComboBox = new ComboBox&lt;&gt;(&quot;Company&quot;);
      companyComboBox.setRequired(true);
      companyComboBox.setItems(new CompanyBackEndDataProvider(companyService));
      companyComboBox.setPageSize(20);
      companyComboBox.setAllowCustomValue(true);
      companyComboBox.setItemLabelGenerator(e -&gt; TranslationUtils.getTranslatedName(e.getNode()));
  </code></pre>
  <p>As you may see, I added CompanyBackEndDataProvider which looks like:</p>
  <pre><code>public class CompanyBackEndDataProvider extends AbstractBackEndDataProvider&lt;CompositeEntityResult, String&gt; {
  
      private final CompanyService companyService;
  
      public CompanyBackEndDataProvider(CompanyService companyService) {
          this.companyService = companyService;
      }
  
      @Override
      protected Stream&lt;CompositeEntityResult&gt; fetchFromBackEnd(Query&lt;CompositeEntityResult, String&gt; query) {
          Stream&lt;CompositeEntityResult&gt; stream = Stream.empty();
          Optional filter = query.getFilter();
          if (filter.isPresent()) {
              int page = query.getPage();
              int pageSize = query.getPageSize();
              String namePattern = (String) filter.get();
              if (StringUtils.isNoneBlank(namePattern)) {
                  List&lt;CompositeEntityResult&gt; compositeEntityResults = companyService.findByNamePattern(namePattern, VaadinUtils.getCurrentLocaleIso6391(), page, pageSize);
                  stream = compositeEntityResults.stream();
              }
          }
          return stream;
      }
  
      @Override
      protected int sizeInBackEnd(Query&lt;CompositeEntityResult, String&gt; query) {
          int size = 0;
          Optional filter = query.getFilter();
          if (filter.isPresent()) {
              String namePattern = (String) filter.get();
              if (StringUtils.isNoneBlank(namePattern)) {
                  size = (int) companyService.findByNamePatternCount(namePattern);
              }
          }
          return size;
      }
  
  }
  </code></pre>
  <p>At first glance everything works fine, but when I have a lot of items for the query term returned, I see the following message in the console when I scroll items a little down:</p>
  <pre><code>WARN 2992 --- [nio-8080-exec-7] c.v.flow.data.provider.DataCommunicator  : Attempted to fetch more items from server than allowed in one go: number of items requested '220', maximum items allowed '200'.
  </code></pre>
  <p>Also, I may see a lot of empty space reserved in the ComboBox popup window with a scroll bar:</p>
  <p><a href="https://i.stack.imgur.com/DdWZF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DdWZF.jpg" alt="enter image description here" /></a></p>
  <p>What am I doing wrong and how to fix it?</p>
  <p><strong>UPDATED</strong></p>
  <p>The same issue I may see, when I change the code to simply:</p>
  <pre><code>companyComboBox.setItems(query -&gt;
          companyService.findByNamePattern(query.getFilter().get(), VaadinUtils.getCurrentLocaleIso6391(), query.getOffset(), query.getLimit()).stream()
  );
  </code></pre>
  <p>Also, when I remove the following line:</p>
  <pre><code>companyComboBox.setPageSize(20);
  </code></pre>
  <p>everything starts working fine.. Strange.. still don't understand the correlation between <code>companyComboBox.setPageSize(20);</code> and the mentioned issue</p>