Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Need Help with Grid cells

Fernando Bonilla
5 years ago Mar 14, 2017 1:42am
Ian Scriven
5 years ago Mar 14, 2017 6:12am
Fernando Bonilla
5 years ago Mar 14, 2017 9:01pm
Ian Scriven
5 years ago Mar 14, 2017 9:23pm

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
...
  

Hope that helps