How to bind checkbox with boolean property set on a bean?

Hi, I am having this issue with databinding. I have an OptionGroup that, depending on the radiobutton clicked, it will set a boolean value to an attribute on an existing bean. I have a checkbox, that I want to get it’s status from this boolean property. My bean has implemented the Property interface, and this are the implemented methods:

@Override
public void setValue(Object newValue) throws ReadOnlyException {
    if ( newValue instanceof Boolean){
        status.setChecked((boolean)newValue);
        System.out.println("Value del property setValue Boolean="+(boolean)newValue);
    }else
        throw new ConversionException("Could not convert between Task and Boolean");
}

@Override
public Object getValue() {
    System.out.println("Value del property ="+status.isChecked());
    return status.isChecked();
}

When I do click on the radio button, it prints "Value del property setValue Boolean=false " or “Value del property setValue Boolean=true” depending on the value that the radiobutton set. That is correct, but I cant see that the checkbox is rendered with the value, it remains unchecked also when the value returned is TRUE.
On Checkbox I set the Property using setpropertyDataSource:

checkSharedLibCheck.setPropertyDataSource(presenter.getTaskProperty(TasksConfig.CHECK_SHAREDLIB));

Checkbox has the immediate set to true, and the setBuffered on false.

What I am doing wrong? If you have suggestions or examples, I would be thankful.

Thanks,
Celeste.-

Hi Celeste.

From your code snippet it is hard to know what exactly you have in place now, so I’m just guessing on what you might have there.

You shouldn’t need to implement the Property interface yourself, and the Property interface only defines that the Property has a type and a value. To get automatic updating of all Components (implementing Property.Viewer and Property.ValueChangeListener) which are bound to the Property, the Property has to implement the Property.ValueChangeNotifier. You should not need to implement these yourself, as the most components in Vaadin implement the proper interfaces.

Since you are somehow binding together a single select optiongroup (radio buttons) and a checkbox, you can use the same property/bean for both and then apply a converter on either one of the fields (depending on the actual type of the property).

For examples, I recommend the book of Vaadin
chapter on data binding
or the
form and data binding
examples on Vaadin wiki.

Hi Pekka, thanks for your answer. I will better describe what I want to do. I have a radio button and a check box. When the radio button is checked, a boolean attribute from an object is modified ( it can be true or false, depending of other values). I want the checkbox to be updated when this boolean is modified. If the boolean attribute is true, I want the checkbox to be checked, and instead if it is false, the checkbox not to be checked. I dont know how this can be done? I read the chapters you mentioned, but nothing works.
Thanks,
Celeste.-