(New in Vaadin) I have a Grid with an IndexedContainer. This Grid is planned to be filled with the user information and then stored. It has a button to add as many rows as the user need. The problem is that some columns have to be ComboBoxes, cells accepting only Hour format and a Button. Something like this:
For the hour format, you’ll need to use a converter (StringToIntegerConverter) and validator (IntegerRangeValidator) for each column. How you do that will depend on whether you are using Vaadin 7 or 8.
Based on your other post in this forum I’m going to guess you’re planning on using Vaadin 8.
(I’m writing this code on the directly here, so there might be some syntax errors) (also I’m new to Vaadin 8 so there might be better/cleaner ways of doing this)
// the bean in the grid
public class GridRow {
private int hours; // 0 - 23
// other data
public int getHours() { return hours; }
public void setHours(int hours) { this.hours = hours; }
}
// in the view/UI
...
Grid<GridRow> grid = new Grid<>(GridRow.class);
Binder<GridRow> binder = grid.getEditor().getBinder();
TextField hoursField = new TextField();
// in Vaadin 7 you'd add the Converter/Validator directly to the TextField
Binder.Binding<GridRow, Integer> hoursBinding = binder.forField(hoursField)
.withConverter(new StringToIntegerConverter)
.withValidator(new IntegerRangeValidator("Value must be between 0 and 23", 0, 23))
.bind(Person::getHours, Person::setHours);
// in Vaadin 7 you'd do grid.addColumn("hours").setEditorField(hoursField)
grid.addColumn("hours").setEditorBinding(hoursBinding);
// enable grid editing, define listeners for editing events
...