From 666ae3f5f89e4ac433fe58c71547c7a96e2ab30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Fri, 23 Aug 2024 12:59:54 +0200 Subject: [PATCH] fix: make radio button group with size request serializable (#6571) --- .../component/radiobutton/RadioButtonGroup.java | 12 +++++++++--- .../tests/RadioButtonSerializableTest.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) 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 dccc459c0b4..23e815bd376 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 @@ -608,9 +608,15 @@ private void rebuild() { // Ignore new size requests unless the last one has been executed // so as to avoid multiple beforeClientResponses. if (sizeRequest == null) { - sizeRequest = ui -> { - fireSizeEvent(); - sizeRequest = null; + // Using anonymous class to fix serialization issue: + // https://github.com/vaadin/flow-components/issues/6555 + // Do not replace with lambda + sizeRequest = new SerializableConsumer<>() { + @Override + public void accept(UI ui) { + fireSizeEvent(); + sizeRequest = null; + } }; // Size event is fired before client response so as to avoid // multiple size change events during server round trips diff --git a/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/tests/RadioButtonSerializableTest.java b/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/tests/RadioButtonSerializableTest.java index 1ad541252f2..ca5d3c1c0de 100644 --- a/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/tests/RadioButtonSerializableTest.java +++ b/vaadin-radio-button-flow-parent/vaadin-radio-button-flow/src/test/java/com/vaadin/flow/component/radiobutton/tests/RadioButtonSerializableTest.java @@ -15,7 +15,23 @@ */ package com.vaadin.flow.component.radiobutton.tests; +import org.junit.Test; + +import com.vaadin.flow.component.UI; +import com.vaadin.flow.component.radiobutton.RadioButtonGroup; import com.vaadin.flow.testutil.ClassesSerializableTest; public class RadioButtonSerializableTest extends ClassesSerializableTest { + @Test + public void setItems_addToUI_radioButtonGroupIsSerializable() + throws Throwable { + var group = new RadioButtonGroup<>(); + group.setItems("Item 1", "Item 2"); + + var ui = new UI(); + UI.setCurrent(ui); + ui.add(group); + + serializeAndDeserialize(ui); + } }