Reset RadioButtonGroup

Hi,

Is there a way to reset a RadioButtonGroup? In other words, programatically unselect the user choice.

I tried clear() and setSelectedItem(null) without success (the UI always shows the selection).

Thx

Hi JC,

trying Vaadin Framework 8.0.6 and the following code:

package com.example.myapplication;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.RadioButtonGroup;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

/**
 * This UI is the application entry point. A UI may either represent a browser window
 * (or tab) or some part of a html page where a Vaadin application is embedded.
 * <p>
 * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be
 * overridden to add component to the user interface and initialize non-component functionality.
 */
@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();
        
        final TextField name = new TextField();
        name.setCaption("Type your name here:");

        final RadioButtonGroup<String> single = new RadioButtonGroup<>("Single Selection");
        single.setItems("Single", "Sola", "Yksi");
        
        Button button = new Button("Click Me");
        button.addClickListener(e -> {
            
            System.out.println(single.getSelectedItem());
            single.setSelectedItem(null);
            System.out.println(single.getSelectedItem());
            
                
        });
        
        layout.addComponents(name, button, single);
        
        setContent(layout);

    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}

I think you have a valid point.

Select Yksi, press button:
Optional[Yksi]

Optional.empty

Press button:
Optional.empty
Optional.empty

but the graphical representation stays at “Yksi”.

Let’s make this a bug: https://github.com/vaadin/framework/issues/9494

Thank you + Best Regards,
–Enver

Thx for the follow-up