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

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

Rebinding fields in a FieldGroup -- exception concurrent modification

David Wall
5 years ago Oct 10, 2016 5:56pm
David Wall
5 years ago Oct 10, 2016 6:08pm
David Wall
5 years ago Oct 10, 2016 10:42pm

RESOLVED, but odd didn't need this before when using the deprecated Form subclassing, but has the issue using FieldGroup.

It turns out that one of the fields (a select box) has a value change listener that updates some of the UI based on the selected value.  When doing a fieldGroup.setItemDataSource, this causes the value to change and that select's ValueChangeListener to trigger, which then tries to update the field group.  This caused the concurrent modification exception.

To get around this, I have a variable that I set just before I call fieldGroup.setItemDataSource and unset after it returns so the select's ValueChangeListener can test that variable and skip doing the related fieldgroup changes.

So my handler for new items is:

public void setItemDataSource(Item newDataSource) { // called when reloading a form so we can build a type-appropriate version
        doingNewItemDataSource = true;
        if ( newDataSource != null ) {
        } else {
        doingNewItemDataSource = false;

and then my select's value change is:

reportFieldTemplateId.addValueChangeListener( new ValueChangeListener() {
            public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
                EsfUUID newReportFieldTemplateId = (EsfUUID)event.getProperty().getValue();
                if ( newReportFieldTemplateId != null && ! newReportFieldTemplateId.isNull() ) {
                    if ( ! doingNewItemDataSource )