I use Vaadin
framework v23 for my project.
A wanted to add a component column to one of my Grids, a number field. My Grid's rows are representing an entity from the database my program connected to. I ask for an input from the user, and I want to write that input back to the DB. I found this solution at several sites:
private Grid<Honey> initHoneyGrid() {
Grid<Honey> honeyGrid = new Grid<>(Honey.class);
honeyGrid.setItems(honeys);
honeyGrid.removeColumnByKey("id");
honeyGrid.removeColumnByKey("quantityPacked");
honeyGrid.removeColumnByKey("flatCost");
honeyGrid.removeColumnByKey("sellingPrice");
honeyGrid.setColumns("kindOfHoney", "weight", "quantityBack");
honeyGrid.addComponentColumn(item -> new NumberField("Set the quantity you brought back'", event -> {
item.setQuantityBack(event.getValue().intValue());
honeyService.updateHoney(item);
honeyGrid.getDataProvider().refreshAll();
}));
return honeyGrid;
}
However, the variable "item" throws NullPointerException. The "honeys" variable is an ArrayList, which is filled from the DB directly. I use Spring Boot JPA to access the database. How can I avoid it?