use of com.vaadin.flow.component.crud.CrudEditor in project flow-components by vaadin.
the class Helper method createPersonEditor.
static CrudEditor<Person> createPersonEditor() {
TextField firstName = new TextField("First name");
firstName.getElement().setAttribute("editor-role", "first-name");
TextField lastName = new TextField("Last name");
lastName.getElement().setAttribute("editor-role", "last-name");
FormLayout form = new FormLayout(firstName, lastName);
Binder<Person> binder = new Binder<>(Person.class);
binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
binder.forField(lastName).withValidator(value -> value != null && value.startsWith("O"), "Only last names starting with 'O' allowed").bind(Person::getLastName, Person::setLastName);
return new BinderCrudEditor<>(binder, form);
}
Aggregations