How is the correct way to save a Vaadin CheckBox to JPA’
I’m looking to find a Vaadin example but I didn’t find any using of Checkbox to JPA at all.
I try this but is work only if I click one time on a checkbox, if click again on the same box is breaks off
private Grid createGrid() {
grid = new Grid<>();
ListDataProvider<User> dataProvider = DataProvider.ofCollection(userRepository.findAll());
grid.setDataProvider(dataProvider);
grid.setHeight("100%");
grid.setMaxWidth("840px");
grid.addColumn(new ComponentRenderer<>(this::createUserInfo)).setWidth(UIUtils.COLUMN_WIDTH_XL);
grid.addComponentColumn(u -> {
Checkbox c = new Checkbox();
c.getStyle().set("font-size", "24px");
c.setValue(u.isAnwesend());
c.addValueChangeListener(click -> {
changeIsAnwesend(u);
});
return c;
})
.setFlexGrow(0)
.setWidth(UIUtils.COLUMN_WIDTH_XS);
grid.addThemeVariants(GridVariant.LUMO_NO_ROW_BORDERS);
return grid;
}
private void changeIsAnwesend(User user) {
user.setAnwesend(!user.isAnwesend());
//grid.setSelectionMode(Grid.SelectionMode.SINGLE).select(user);
userRepository.save(user);
}