use of com.vaadin.data.validator.EmailValidator in project vaadin-samples by xpoft.
the class SimpleForm method PostConstruct.
@PostConstruct
public void PostConstruct() {
User user = new User();
setCaption("Simple form");
setSpacing(true);
TextField name = new TextField("Name");
name.setRequired(true);
name.setRequiredError("Please enter a Name!");
name.setWidth(COMMON_FIELD_WIDTH);
name.addValidator(new StringLengthValidator("It must be 3-25 characters", 3, 25, false));
name.setNullRepresentation("");
name.setImmediate(true);
TextField email = new TextField("Email:");
email.setRequired(true);
email.setRequiredError("Please enter a Email");
email.setWidth(COMMON_FIELD_WIDTH);
email.addValidator(new EmailValidator("Not valid email"));
email.setNullRepresentation("");
email.setImmediate(true);
final BeanFieldGroup<User> fieldGroup = new BeanFieldGroup<User>(User.class);
fieldGroup.setItemDataSource(new BeanItem<User>(user));
fieldGroup.bind(name, "name");
fieldGroup.bind(email, "email");
// The cancel / apply buttons
HorizontalLayout buttons = new HorizontalLayout();
buttons.setSpacing(true);
Button discardChanges = new Button("Reset", new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
fieldGroup.discard();
}
});
buttons.addComponent(discardChanges);
buttons.setComponentAlignment(discardChanges, Alignment.MIDDLE_LEFT);
Button apply = new Button("Save", new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
try {
fieldGroup.commit();
Notification.show("OK");
} catch (Exception e) {
Notification.show("Error: " + e.getMessage(), Notification.Type.WARNING_MESSAGE);
}
}
});
buttons.addComponent(apply);
addComponent(name);
addComponent(email);
addComponent(buttons);
}
Aggregations