Change form biding to use BeanValidationBinder
This commit is contained in:
parent
9d258aa505
commit
d46ff97367
|
@ -9,6 +9,7 @@ import com.vaadin.flow.component.icon.VaadinIcon;
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
|
import com.vaadin.flow.data.binder.BeanValidationBinder;
|
||||||
import com.vaadin.flow.data.binder.Binder;
|
import com.vaadin.flow.data.binder.Binder;
|
||||||
|
|
||||||
public class EmployeeEditor extends Composite<VerticalLayout> {
|
public class EmployeeEditor extends Composite<VerticalLayout> {
|
||||||
|
@ -31,7 +32,7 @@ public class EmployeeEditor extends Composite<VerticalLayout> {
|
||||||
private DeleteListener deleteListener;
|
private DeleteListener deleteListener;
|
||||||
private CancelListener cancelListener;
|
private CancelListener cancelListener;
|
||||||
|
|
||||||
private final Binder<Employee> binder = new Binder<>(Employee.class);
|
private final Binder<Employee> binder = new BeanValidationBinder<>(Employee.class);
|
||||||
|
|
||||||
public EmployeeEditor() {
|
public EmployeeEditor() {
|
||||||
var firstName = new TextField("First name");
|
var firstName = new TextField("First name");
|
||||||
|
@ -41,8 +42,8 @@ public EmployeeEditor() {
|
||||||
var cancel = new Button("Cancel");
|
var cancel = new Button("Cancel");
|
||||||
var delete = new Button("Delete", VaadinIcon.TRASH.create());
|
var delete = new Button("Delete", VaadinIcon.TRASH.create());
|
||||||
|
|
||||||
binder.forField(firstName).bind(Employee::getFirstName, Employee::setFirstName);
|
binder.forField(firstName).bind("firstName");
|
||||||
binder.forField(lastName).bind(Employee::getLastName, Employee::setLastName);
|
binder.forField(lastName).bind("lastName");
|
||||||
|
|
||||||
save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
save.addClickListener(e -> save());
|
save.addClickListener(e -> save());
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class EmployeesView extends VerticalLayout {
|
||||||
addButton.addClickListener(e -> editEmployee(new Employee()));
|
addButton.addClickListener(e -> editEmployee(new Employee()));
|
||||||
|
|
||||||
filter.setPlaceholder("Filter by last name");
|
filter.setPlaceholder("Filter by last name");
|
||||||
filter.setValueChangeMode(ValueChangeMode.EAGER);
|
filter.setValueChangeMode(ValueChangeMode.LAZY);
|
||||||
filter.addValueChangeListener(e -> updateEmployees(e.getValue()));
|
filter.addValueChangeListener(e -> updateEmployees(e.getValue()));
|
||||||
|
|
||||||
grid.setHeight("200px");
|
grid.setHeight("200px");
|
||||||
|
|
Loading…
Reference in New Issue