在Vaadin 7中有一个addValidator函数,但在Vaadin 8中它不存在.
Vaadin 7示例:
TextField user = new TextField("User:");
user.setRequired(true);
user.setInputPrompt("Your username");
user.addValidator(new NullValidator("Username can't be empty", false));
user.setInvalidAllowed(false);
Run Code Online (Sandbox Code Playgroud) 我正在用vaadin创建一个Java项目.现在我有一个用户注册表格,如下所示:
public class RegistrationComponent extends CustomComponent implements View {
public static final String VIEW_NAME = "Registration";
public RegistrationComponent(){
Panel panel = new Panel("Registration Form");
panel.setSizeUndefined();
FormLayout content = new FormLayout();
CheckBox checkBox1, checkBox2, checkBox3;
checkBox1 = new CheckBox("Check Box 1");
checkBox2 = new CheckBox("Check Box 2");
checkBox3 = new CheckBox("Check Box 3");
checkBox1.setRequired(true);
checkBox2.setRequired(true);
TextField mailTextField = new TextField("Email Address");
TextField passwordTextField = new TextField("Password");
TextField confirmPasswordTextField = new TextField("Confirm Password");
final Button submitButton = new Button("Submit");
content.addComponent(mailTextField);
content.addComponent(passwordTextField);
content.addComponent(confirmPasswordTextField); …Run Code Online (Sandbox Code Playgroud)