Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select component uses old instance to refresh item #6579

Open
heruan opened this issue Aug 27, 2024 · 2 comments
Open

Select component uses old instance to refresh item #6579

heruan opened this issue Aug 27, 2024 · 2 comments

Comments

@heruan
Copy link
Member

heruan commented Aug 27, 2024

Description

When Select reacts to a DataChangeEvent (i.e. DataProvider.refresh(item)) the callback does not take into account the new item instance but it just re-render the existing instance.

See in

private void onDataChange(DataChangeEvent<T> event) {
if (event instanceof DataChangeEvent.DataRefreshEvent) {
T updatedItem = ((DataChangeEvent.DataRefreshEvent<T>) event)
.getItem();
IdentifierProvider<T> identifierProvider = getIdentifierProvider();
Object updatedItemId = identifierProvider.apply(updatedItem);
getItems()
.filter(vaadinItem -> updatedItemId.equals(
identifierProvider.apply(vaadinItem.getItem())))
.findAny().ifPresent(this::updateItem);
} else {
reset();
}
}

The updatedItem is only used to find the corresponding existing vaadinItem and then the updateItem is invoked with the existing vaadinItem instance, so that if anything has changed in updatedItem it’s just ignored.

Expected outcome

Upon DataChangeEvent the new data is used to update the item.

Minimal reproducible example

var select = new Select("Test");
select.setDataProvider(dp);
dp.refreshItem(newItem);

Steps to reproduce

The data provider needs to override the getId method so that the newItem instance matches an existing item, but the update still uses the old instance.

Environment

Vaadin version(s): 24.5.0.alpha10

Browsers

No response

@yuriy-fix
Copy link
Contributor

Might need to be verified in e.g. ComboBox

@MatthewVaadin
Copy link

There is possibly another issue with the onDataChange method. When a refreshAll() is called on the data provider, the select is reset (the else branch), which includes clearing the selected value. I would expect the selected value to remain selected if the value still exists. This is what happens with a combo box.

See minimal example here: https:/MatthewVaadin/refresh-select

Steps to reproduce:

  1. Select an option in both the select (above) and the combo box (below).
  2. Click the "Refresh items" button.
  3. Observe that the value is cleared in the select, but not in the combo box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants