com.vaadin.data.

Interface HasItems<T>

    • Method Detail

      • getDataProvider

        DataProvider<T,​?> getDataProvider()

        Returns the source of data items used by this listing.

        Returns:

        the data provider, not null

      • setItems

        void setItems​(Collection<T> items)

        Sets the data items of this component provided as a collection.

        The provided items are wrapped into a ListDataProvider and this instance is used as a data provider for the HasDataProvider.setDataProvider(DataProvider) method. It means that the items collection can be accessed later on via ListDataProvider.getItems():

         
         HasDataProvider<String> listing = new CheckBoxGroup<>();
         listing.setItems(Arrays.asList("a","b"));
         ...
        
         Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
         
         

        The provided collection instance may be used as-is. Subsequent modification of the collection might cause inconsistent data to be shown in the component unless it is explicitly instructed to read the data again.

        Parameters:

        items - the data items to display, not null

      • setItems

        default void setItems​(T... items)

        Sets the data items of this listing.

        The provided items are wrapped into a ListDataProvider and this instance is used as a data provider for the HasDataProvider.setDataProvider(DataProvider) method. It means that the items collection can be accessed later on via ListDataProvider.getItems():

         
         HasDataProvider<String> listing = new CheckBoxGroup<>();
         listing.setItems("a","b");
         ...
        
         Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
         
         

        Parameters:

        items - the data items to display

        See Also:

        setItems(Collection)

      • setItems

        default void setItems​(Stream<T> streamOfItems)

        Sets the data items of this listing provided as a stream.

        This is just a shorthand for setItems(Collection), that collects objects in the stream to a list. Thus, using this method, instead of its array and Collection variations, doesn't save any memory. If you have a large data set to bind, using a lazy data provider is recommended. See BackEndDataProvider for more info.

        The provided items are wrapped into a ListDataProvider and this instance is used as a data provider for the HasDataProvider.setDataProvider(DataProvider) method. It means that the items collection can be accessed later on via ListDataProvider.getItems():

         
         HasDataProvider<String> listing = new CheckBoxGroup<>();
         listing.setItems(Stream.of("a","b"));
         ...
        
         Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
         
         

        Parameters:

        streamOfItems - the stream of data items to display, not null

        See Also:

        setItems(Collection)