diff --git a/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/main/java/com/vaadin/flow/component/radiobutton/RadioButtonGroup.java b/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/main/java/com/vaadin/flow/component/radiobutton/RadioButtonGroup.java index 95420580b02..e573ffd9ea6 100755 --- a/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/main/java/com/vaadin/flow/component/radiobutton/RadioButtonGroup.java +++ b/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/main/java/com/vaadin/flow/component/radiobutton/RadioButtonGroup.java @@ -856,10 +856,9 @@ public void onDiscard(DataChangeEvent dataChangeEvent) { } private void handleDataChange(DataChangeEvent dataChangeEvent) { - if (dataChangeEvent instanceof DataChangeEvent.DataRefreshEvent) { - resetRadioButton( - ((DataChangeEvent.DataRefreshEvent) dataChangeEvent) - .getItem()); + if (dataChangeEvent instanceof DataChangeEvent.DataRefreshEvent refreshEvent) { + keyMapper.refresh(refreshEvent.getItem()); + resetRadioButton(refreshEvent.getItem()); } else { keyMapper.removeAll(); selectionPreservationHandler.handleDataChange(dataChangeEvent); diff --git a/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/RadioButtonGroupTest.java b/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/RadioButtonGroupTest.java index d077f9cb78b..8ed9f4ba266 100755 --- a/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/RadioButtonGroupTest.java +++ b/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/RadioButtonGroupTest.java @@ -601,4 +601,27 @@ public void preserveAllSelectionOnDataChange_noExtraChangeEventsFired() { Assert.assertEquals(selectedItem, group.getValue()); Assert.assertTrue(events.isEmpty()); } + + @Test + public void refreshItem_selectFromClient_valueContainsUpdatedItem() { + RadioButtonGroup group = new RadioButtonGroup<>(); + RadioButtonGroupListDataView dataView = group.setItems( + new CustomItem(1L, "foo"), new CustomItem(2L, "bar"), + new CustomItem(3L, "baz")); + dataView.setIdentifierProvider(CustomItem::getId); + + CustomItem updatedItem = new CustomItem(2L, "updated"); + dataView.refreshItem(updatedItem); + + AtomicReference selectedItem = new AtomicReference<>(); + group.addValueChangeListener(e -> selectedItem.set(e.getValue())); + + // Simulate selecting an item from the client side via key + String itemKey = group.getChildren().skip(1).findFirst().orElseThrow() + .getElement().getProperty("value"); + group.getElement().setProperty("value", itemKey); + + Assert.assertEquals("updated", selectedItem.get().getName()); + Assert.assertEquals("updated", group.getValue().getName()); + } }