Skip to content

Commit

Permalink
Extra 5 | Handle default and null selection in grid
Browse files Browse the repository at this point in the history
  • Loading branch information
amahdy committed Jun 1, 2017
1 parent f9308f4 commit 27a5318
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/vaadin/stepbystep/MyUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ public class MyUI extends UI {
protected void init(VaadinRequest vaadinRequest) {

listPersons();
selectDefault();

grid.asSingleSelect().addValueChangeListener(evt -> {
editorView.setPerson(evt.getValue());
Person value = evt.getValue();
if(value==null) {
selectDefault();
}else {
editorView.setPerson(value);
}
});

splitPanel.setSizeFull();
Expand All @@ -55,6 +61,12 @@ protected void init(VaadinRequest vaadinRequest) {

}

private void selectDefault() {
Person first = service.getFirst();
grid.select(first);
editorView.setPerson(first);
}

private void listPersons() {
grid.setItems(service.getEntries());
}
Expand Down

0 comments on commit 27a5318

Please sign in to comment.