Error with binder component

Hi,

I’m trying to set up an button in a grid which is for changing a value in the grid.
The user pushes the button, get’s to change the value in the grid and saves his changes.
When I activate the binder the site crashes with DefaultErrorHandler:34 - java.util.ConcurrentModificationException.
The code looks like this:

	private Button createEditButton(Grid<AtcParameter> grid, AtcParameter parameter) {
		binder = new Binder<>(AtcParameter.class);
		editor.setBinder(binder);
		editor.setBuffered(true);
		
		TextField field = new TextField();
		binder.forField(field);
		para.setEditorComponent(field);
		
		Button edit = new Button(bundle.getString("SETTINGS_BUTTON_EDIT"));
		edit.addClickListener(e -> {
			editor.editItem(parameter);
			field.setValue(parameter.getParameter1());
			field.focus();
		});
    edit.setEnabled(!editor.isOpen());
		return edit;
	}

I don’t know where I’m doing it wrong.
Best regards
Daniel

Hi Daniel

binder.forField(field); this is not enough, you need to call .bind(getter, setter) after the forField.
For non-nested properties of AtcParameter (and as long you don’t need further configuration of the binding like converters, validator, nullRepresentation), you could also use this short form: binder.bind(field, getter, setter);.

See [here]
(https://vaadin.com/docs/v13/flow/binding-data/tutorial-flow-components-binder.html) for the documentation.

binder.forField(field).bind(AtcParameter::getParameter1, AtcParameter::setParameter1);

Another possible problem is the mixed functionality of the method createEditButton. I assume that this code is used to add such a button to each row of the grid, using a ComponentRenderer? If that is correct, then I would refrain from doing anything else besides creating the button and returning it. If your grid contains 10 items, then you basically defined a editor binder 10 times, defined the editorComponent for the para column 10 times, etc. I could even imagine that your ConcurrentModificationException is caused by this.
Instead, prepare the grid’s editor and all the editorComponents for each editable column directly after creating the grid. The [example for Grid Editor in buffered mode]
(https://vaadin.com/components/vaadin-grid/java-examples/grid-editor) shows this very well.

Hi,

after a few changes to the example you mentioned it is working just fine.

Thank you