Skip to content

Instantly share code, notes, and snippets.

@macprzepiora
Last active June 11, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macprzepiora/665597644c9e7b39c2746872a579f149 to your computer and use it in GitHub Desktop.
Save macprzepiora/665597644c9e7b39c2746872a579f149 to your computer and use it in GitHub Desktop.
Vaadin 10 code showing an issue with required TextField https://github.com/vaadin/vaadin-text-field-flow/issues/82
package eu.przepiora.mac;
import com.vaadin.flow.component.dependency.HtmlImport;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.Route;
@HtmlImport("styles/shared-styles.html")
@Route("")
public class MainView extends VerticalLayout {
public MainView() {
Binder<PersonBean> binder = new Binder<>(PersonBean.class);
PersonBean joeDeveloper = new PersonBean();
joeDeveloper.setFirstName("Joe");
joeDeveloper.setLastName("Developer");
binder.setBean(joeDeveloper);
TextField firstName = new TextField();
TextField lastName = new TextField();
binder.forField(firstName)
.withValidator(s -> s.equals("Joe"), "Must be Joe")
.asRequired()
.bind("firstName");
binder.forField(lastName).bind("lastName");
add(firstName, lastName);
}
public static class PersonBean {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment