Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
listner for radio button
hi,
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("Today");
list.addItem("7 Days");
list.addItem("30 Days");
list.addItem("Custom");
list.select("Custom");
is listener avaiable for radio button??
please help me
regard
srikaanth
Option group has a value change listener just like any other vaadin field, and inside that you can check if value equals "Custom".
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");
text.setEnabled(false);
final OptionGroup optiongroup = new OptionGroup("");
optiongroup.setMultiSelect(false); [color=#2db93f]//if true, vaadin creates checkboxes, if false, Vaadin creates radio buttons[/color]
optiongroup.addItem("A");optiongroup.addItem("B");optiongroup.addItem("C");
optiongroup.[color=#ed1a52]setImmediate(true);[/color] [color=#2db93f]// Do not forget this line ! without it the click event is not send to the listener[/color]
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[/color]
else text.setEnabled(false); [color=#2db93f]//Otherwise, the texfield is still disabled[/color]
}});
Eric
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 https://vaadin.com/forum#!/thread/3603213