Skip to content

Commit

Permalink
Extra 7 | Add cancel event
Browse files Browse the repository at this point in the history
  • Loading branch information
amahdy committed Jun 2, 2017
1 parent 5aa3539 commit f3d8304
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/vaadin/stepbystep/MyUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class MyUI extends UI {
listPersons();
grid.select(save);

}, person -> {
Person original = service.getById(person.getId());
grid.getDataProvider().refreshItem(original);
return original;
});

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/vaadin/stepbystep/PersonEditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.vaadin.stepbystep.person.backend.Person;

import java.util.function.Consumer;
import java.util.function.Function;

/**
* Created by amahdy on 6/1/17.
Expand All @@ -13,10 +14,12 @@ public class PersonEditorView extends PersonEditorDesign {

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

public PersonEditorView(Consumer<Person> consumer) {
public PersonEditorView(Consumer<Person> saveEvt,
Function<Person, Person> cancelEvt) {
binder.bindInstanceFields(this);

save.addClickListener(evt -> consumer.accept(binder.getBean()));
save.addClickListener(evt -> saveEvt.accept(binder.getBean()));
cancel.addClickListener(evt -> setPerson(cancelEvt.apply(binder.getBean())));
}

public void setPerson(Person value) {
Expand Down

0 comments on commit f3d8304

Please sign in to comment.