Skip to content

Grid does not correctly notify ItemCountChangeListener if wrapped in Composite #24292

@thomasdewaelheyns

Description

@thomasdewaelheyns

Description

When using a Composite, it does not correctly notify the subscribed ItemCountChangeListeners. The addItemCountChangeListener from AbstractDataView subscribes to the instance of Grid, while the fireItemCountEvent inside the DataCommunicator fires the event on the class extending the Composite. As such, no listeners are notified.

A current workaround is calling
ComponentUtil.addListener(this, ItemCountChangeEvent.class, (ComponentEventListener) event -> handleCountEvent();
from the extending class.

Expected outcome

Even when using Grid inside a composite, the ItemCountChangeListeners should be notified.

Minimal reproducible example

public ExampleGrid extends Composite<Grid<TestObject>> {
    public ExampleGrid(){
        //The below never fires
        getContent().getGenericDataView().addItemCountChangeListener(event ->
                createFooters(getContent().getGenericDataView().getItems().toList()));
        //The below is correctly notified
        ComponentUtil.addListener(this, ItemCountChangeEvent.class, (ComponentEventListener) event ->
                handleCountEvent();
    }
}

Steps to reproduce

  1. Create a class extending Composite
  2. In this class, add an ItemCountChangeListener
  3. Make something change the item count
  4. Notice that the ItemCountChangeListener is not fired.

Environment

Vaadin version(s): 24.9.10
OS: Windows 11

Browsers

Issue is not browser related

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status

    🔖 Low Priority (P3)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions