Issues about RadioButtonGroup

Hi, I am using RadioButtonGroup in V14. I would like to pre-set the RadioButtonGroup to some initial value. However when I set using radioGroup.setValue(value), the corresponding radio didn’t get marked. How can I have the corresponding radio get marked when I pre-set a value?

Best regards,
Joey

Hi Joey

Can you show us how you initialize your RadioButtonGroup, and where you set the initial value?

If you use a Binding for the RadioButtonGroup, then just set the corresponding value of the bean to the pre-set value. Than you don’t need to use the radioGroup.setValue(…).

Hi,

Here are my codes:

binder.forField( qualification )
	.bind( case -> {
		Set< CaseSource > sources = case.getSources();
		if ( sources.size() > 0 ) {
			String value = sources.iterator().next().getQualification();
			for ( CaseSource source : sources ) {
				if ( source.Isprimary() ) {
					value = source.getQualification();
				}
			}
			qualification.setValue( value );
			return value;
		}
		else {
			return "";
		}
	} ,
	( case , newValue ) -> {
	} );
	qualification.setReadOnly( true );

Before calling this, I already set the bean to the specified entity. All other binding fields, like TextField, all went well. Any suggestions?

Best regards,
Joey

Joey Chen:

			qualification.setValue( value );
			return value;

You don’t have to call qualification.setValue(value); at all. This is the valueprovider, returning the correct value is enough, the binder will then call setValue itself at some point. As a rule of thumb: You’ll never have to call setValue on any input component that is bound with a Binder.

However, this should have no effect, there must probably be something else going wrong as well, if the radiobuttongroup has not selected the qualification value of your primary CaseSource. Did you set any items for the radiobuttongroup? → If there are no items set, then no value can be selected. If you (or the binder) call setValue("test") but there is no item “test” already set in the radiobuttongroup, it will not create such an item.

If you did set items for the radiobuttongroup before, then maybe the valueprovider returns a different qualification value than you expected. Have you debugged this to make absolutely sure that the returned value from the valueprovider is already present as an item of the radiobuttongroup?

THanks a lot. I set items in the template, and I thought that I don’t need to set them on the server side.

Thanks again.
Joey