【发布时间】:2015-05-12 13:45:49
【问题描述】:
我正在使用 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);
content.addComponent(checkBox1);
content.addComponent(checkBox2);
content.addComponent(checkBox3);
content.addComponent(submitButton);
content.setSizeUndefined(); // Shrink to fit
content.setMargin(true);
panel.setContent(content);
setCompositionRoot(panel);
//listeners:
submitButton.addClickListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
//
}
});
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event){
//
}
}
当然,表单除了显示之外什么都不做。 我想做的是,如果不满足某些要求,让 Vaadin 在字段旁边显示错误消息。要求本身并不那么重要(假设我希望电子邮件字段至少包含 8 个字符)。我想知道的是:有没有简单的内置方法可以做到这一点?我到过这里: https://vaadin.com/api/com/vaadin/data/Validator.html
但我不明白如何使用验证器,或者即使那是我想要使用的。我一直在谷歌上寻找使用示例,但到目前为止没有成功。感谢您的帮助!
【问题讨论】:
标签: java forms validation vaadin vaadin7