Skip to content

Commit

Permalink
Step 10 | 10:01 | Save modifications in the form
Browse files Browse the repository at this point in the history
  • Loading branch information
amahdy committed Jun 1, 2017
1 parent d497b26 commit e658130
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/vaadin/stepbystep/MyUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ public class MyUI extends UI {

HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
Grid<Person> grid = new Grid<>(Person.class);
PersonEditorView editorView = new PersonEditorView();
PersonEditorView editorView = new PersonEditorView(person -> {

Person save = service.save(person);
listPersons();
grid.select(save);

});

@Override
protected void init(VaadinRequest vaadinRequest) {

grid.setItems(service.getEntries());
listPersons();

grid.asSingleSelect().addValueChangeListener(evt -> {
editorView.setPerson(evt.getValue());
Expand All @@ -48,4 +54,8 @@ protected void init(VaadinRequest vaadinRequest) {
setContent(splitPanel);

}

private void listPersons() {
grid.setItems(service.getEntries());
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/vaadin/stepbystep/PersonEditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import com.vaadin.data.Binder;
import org.vaadin.stepbystep.person.backend.Person;

import java.util.function.Consumer;

/**
* Created by amahdy on 6/1/17.
*/
public class PersonEditorView extends PersonEditorDesign {

Binder<Person> binder = new Binder<>(Person.class);

public PersonEditorView() {
public PersonEditorView(Consumer<Person> consumer) {
binder.bindInstanceFields(this);

save.addClickListener(evt -> consumer.accept(binder.getBean()));
}

public void setPerson(Person value) {
Expand Down

0 comments on commit e658130

Please sign in to comment.