MyObj is immutable so it is impossible to edit them, however I should be able to swap them in the list. How should I achieve this?
Here is my Vaadin grid:
List<MyOBj> data = new ArrayList<>();
data.add(new MyObj(..));
data.add(new MyObj(..));
Grid<MyOBj> grid = new Grid<>(MyOBj.class);
grid.setItems(data);
grid.getEditor().setEnabled(true);
grid.addColumn(MyObj::someField).setCaption("someField");
Would MyObj mutable I would just bind the editor:
Binder<MyOBj> binder = grid.getEditor().getBinder();
Binding<MyOBj, Boolean> binding = binder.bind(..binding setters/getter..);
column.setEditorBinding(binding);
Now I am looking for something like this:
Binder<MyOBj> binder = grid.getEditor().getBinder();
Binding<MyOBj, Boolean> binding = binder.bind(..creating new Object and put on the given index of the list..);
column.setEditorBinding(binding);
Is that possible somehow?
Two general solutions form the top of my mind:
MyObj
instance based on the current values in the DTO.Binder
to edit a reference to a MyObj
instead of directly editing a MyOjb
. A practical way of doing this, albeit with a small semantic mismatch, is to do Binder<AtomcReference<MyObj>>
.