RadioButtonGroup setting a value not present in the data provider

Hello Everyone,

I’ve made a ‘Generic’ RadioButtonGroup for Yes/No selection and it return a ‘Y’ or ‘N’ value.
Sometimes when initializing the form, it’s possible that I do a setValue() with another value thant the ‘Y’ or ‘N’.
On the screen, nothing is selected and that is ok, but if I do a getSelectedItem(), it return the other value instead of null.

	public static RadioButtonGroup<String> createYesNoField(Layout layout, String caption, String placeHolder,  boolean readOnly) {
		List <String> ynList = Arrays.asList(placeHolder.split("[|]
"));
		RadioButtonGroup<String> rbS = new RadioButtonGroup<String>(caption, ynList);
        rbS.setItemCaptionGenerator(item -> item.equals("N")?"NO":"YES");
        rbS.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
        rbS.setReadOnly(readOnly);
        layout.addComponent(rbS);
        return rbS;
	}
	
	RadioButtonGroup<String> rbg = createYesNoField(this, "Output PDF?:","Y|N", false);
	rbg.addSelectionListener(event -> {System.out.printf("%s | %s | %s | %s\n", 
        		                                             rbg.getValue(), 
        		                                             rbg.getSelectedItem(), 
        		                                             rbg.isEmpty(), 
        		                                             rbg.getOptionalValue()
        		                                             );    
                                                            });
        
     rbg.setSelectedItem("g");	

	

and the output is : g | Optional[g]
| false | Optional[g]

Sometimes when initializing the form, it’s possible that I do a setValue() with another value thant the ‘Y’ or ‘N’.

May I ask why?

Language issues, data comming from an old application (30 years old) that still contains some bugs issues… and very difficult to fix.

Perhaps best to report the issue here as well: https://github.com/vaadin/framework/issues.

In the meanwhile, you could create your own component that extends RadioButtonGroup and overrides getValue.