listner for radio button


i created a list for radio button. i need listner for one radio button for custom button. i attach the code…

OptionGroup list = new OptionGroup(“Select your option”);
list.addItem(“7 Days”);
list.addItem(“30 Days”);

is listener avaiable for radio button??

please help me



Option group has a value change listener just like any other vaadin field, and inside that you can check if value equals “Custom”.

thanks for reply…

Here is an example of code. Warning : it works only if the method setImmediate(true) is used !

Texfield text = new Texfield("I am a textfield disabled by default");

final OptionGroup optiongroup = new OptionGroup("");
		optiongroup.setMultiSelect(false); [color=#2db93f]
//if true, vaadin creates checkboxes, if false, Vaadin creates radio buttons
[/color] [color=#2db93f]
// Do not forget this line ! without it the click event is not send to the listener

		optiongroup.addListener(new Property.ValueChangeListener() {
			public void valueChange(ValueChangeEvent event) {
				if (optiongroup.getValue()=="A") text.setEnabled(true); [color=#2db93f]
 //If A is selected, the textfield becomes enabled
				else text.setEnabled(false);                       [color=#2db93f]
//Otherwise, the texfield is still disabled


Thanks .

I am using Vaadin 7.1.5 and its saying optiongroup.addListener is deprecated, can you please confirm ?

For a ValueChangeListener use: optiongroup.addValueChangeListener. The addListener method of the base Component class was deprecated as of Vaadin 7 in favor of more specific methods like addClickListener, addItemClickListener, addValueChangeListener, addTextChangeListener, …etc.

As the deprecation message says, it is replaced with addValueChangeListener(…).

For vaadin 7.1.5 we have to change the code see!/thread/3603213