Reputation: 1480
I have a simple entity
public class Vulnerability{
private String name;
private int probability;
private int damage;
}
and grid with row editor
Grid<Vulnerability> vulnerabilityGrid = new Grid<Vulnerability>(Vulnerability.class);
vulnerabilityGrid.setColumns("name", "probability", "damage");
Grid.Column nameColumn = vulnerabilityGrid.getColumn("name");
Grid.Column probabilityColumn = vulnerabilityGrid.getColumn("damage");
Grid.Column damageColumn = vulnerabilityGrid.getColumn("probability");
code of binder with binding to fields
Binder<Vulnerability> binderVulnerability = new Binder<Vulnerability>();
TextField nameTextFieldGrid = new TextField(), damageTextFieldGrid = new TextField(), probabilityTextFieldGrid = new TextField();
Binder.Binding<Vulnerability, Integer> probabilityBind = binderVulnerability.forField(probabilityTextFieldGrid).withNullRepresentation("").withConverter(new StringToIntegerConverter(Integer.valueOf(0), "integers only")).bind(Vulnerability::getProbability, Vulnerability::setProbability);
Binder.Binding<Vulnerability, Integer> damageBind = binderVulnerability.forField(damageTextFieldGrid).withNullRepresentation("") .withConverter(new StringToIntegerConverter(Integer.valueOf(0), "integers only")).bind(Vulnerability::getDamage, Vulnerability::setDamage);
nameColumn.setEditorBinding(nameBind);
probabilityColumn.setEditorBinding(probabilityBind);
damageColumn.setEditorBinding(damageBind);
And problem with column order, when I press on row and editor activates I get editor for damage-field on probabilityColumn position and so on.
How can I get fix this problem?
Upvotes: 0
Views: 85
Reputation: 10643
Look to your code here
Grid.Column probabilityColumn = vulnerabilityGrid.getColumn("damage");
Grid.Column damageColumn = vulnerabilityGrid.getColumn("probability");
You are getting "damage" column to reference probabilityColumn
and set it with binding that has getter and setter to probability, as follows.
Binder.Binding<Vulnerability, Integer> probabilityBind = binderVulnerability.forField(probabilityTextFieldGrid).withNullRepresentation("").withConverter(new StringToIntegerConverter(Integer.valueOf(0), "integers only")).bind(Vulnerability::getProbability, Vulnerability::setProbability);
probabilityColumn.setEditorBinding(probabilityBind);
With other column you do vica versa. So it works as coded. As you see, the API in Vaadin Grid and Binder allows this kind of asymmetry since getters and setters can be defined individually, which in your case is a programming error, but in other cases you can exploit this feature.
Upvotes: 0