Loading...
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.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Vaadin 8 / CustomField / Binder issue

Sevket Kizanlik
5 years ago Feb 26, 2017 2:02pm

Hello,

There is a custom field. The custom field has a combo box. The combo box has some items type of MyItemBean. The value of the custom field is set in the combo box's value change listener by .setValue(...) as below.

Item Bean:

public class MyItemBean {

    ...
    private String valueA;
    ...


    public MyItemBean() {}


    ...
    public String getValueA() { return this.valueA; }
    public void setValueA(String value) { this.valueA = value; }
    ...

}

CustomField:

public class MyCustomField extends CustomField<String> {

    ...
    private final ComboBox<MyItemBean> myComboBox = new ComboBox<>();
    ...


    public MyCustomField() { ... }


    private void myComboBoxValueChangeListener(ValueChangeEvent<MyItemBean> event) {
        this.setValue(event.getValue().getValueA(), event.isUserOriginated());
    }

    @override
    protected component initContent() {
        
        ...
        this.myComboBox.addValueChangeListener(this::myComboBoxValueChangeListener);
        ...

    }

}

The custom field is placed in a detail window (simply master / detail approach) and bound to a bean type of MyDetailBean by Binder as below. 

Detail Bean:

public class MyDetailBean {

    ...
    private String detailA;
    ...


    public MyDetailBean() {}


    ...
    public String getDetailA() { return this.detailA; }
    public void setDetailA(String value) { this.detailA = value; }
    ...

}

Detail window:

public class Detail extends Window {

    ...
    private final Binder<MyDetailBean> binder = new Binder<>();
    private final MyCustomField myCustomField = new MyCustomField();
    ...


    public Detail() {
        ...
        this.binder.bind(this.myCustomField, MyDetailBean::getDetailA(), MyDetailBean::setDetailA());
        ...
    }

    ...

}

Expected behavior is MyDetailBean should be updated when user selects another item in the custom field but the binder doesn't notice the value change in the custom field.

The detail window has some other elements like text fields, check boxes, etc. All Vaadin elements updates the detail bean immediately but the custom field doesn't.

How can I solve this issue?

Thank you...

saoussen marouani
3 years ago Aug 06, 2018 4:28pm
Bernhard Kaiba
3 years ago Aug 21, 2018 2:03pm