user1068477
user1068477

Reputation:

Vaadin - Does ComboBox Lazy Load by Default?

Vaadin 7.6.2

BeanItemContainer

BeanItemContainer<CountryBean> countryBeanContainer 
        = new BeanItemContainer<>(CountryBean.class);
countryBeanContainer.addAll(CountryData.list);                
country.setContainerDataSource(countryBeanContainer);
country.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
country.setItemCaptionPropertyId("name");
country.setTextInputAllowed(true);
...
...

CountryBean

public class CountryBean {

    private String value;
    private String name;

    public CountryBean(String value, String name) {
        this.value = value;
        this.name = name;
    }

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getName() {
        return this.name;       
    }

    public void setName(String name) {
        this.name = name;
    }    
}

CountryData

public abstract class CountryData {        
    public static final List<CountryBean> list = 
            Collections.unmodifiableList(Arrays.asList(
                    new CountryBean("AF", "Afghanistan"),
                    new CountryBean("AX", "Åland Islands"),
                    new CountryBean("AL", "Albania"),
                    new CountryBean("DZ", "Algeria"),
                    new CountryBean("AS", "American Samoa"),
                    new CountryBean("AD", "Andorra"),
                    new CountryBean("AO", "Angola"),
                    new CountryBean("AI", "Anguilla"),
                    ...
                    ...

So, I have this setup running in a ComboBox and it works great. But my question is: Is this list of 200+ countries compiled into the client side code, or is it lazy loaded from the server as the user types or pages through the list of choices? I would like to understand how this works, because I may need to have (say) 5 country fields in my UI.

Upvotes: 0

Views: 976

Answers (1)

Henri Kerola
Henri Kerola

Reputation: 4967

ComboBox is handling lazy loading between client side and server out of the box. Only the rows which are visible in the dropdown are fetched from server to client. So when you do filtering or navigate between different pages on the dropdown, it fetches only those rows from the server.

Upvotes: 1

Related Questions