Example usage for com.vaadin.tests.data.bean PersonWithBeanValidationAnnotations PersonWithBeanValidationAnnotations

List of usage examples for com.vaadin.tests.data.bean PersonWithBeanValidationAnnotations PersonWithBeanValidationAnnotations

Introduction

In this page you can find the example usage for com.vaadin.tests.data.bean PersonWithBeanValidationAnnotations PersonWithBeanValidationAnnotations.

Prototype

public PersonWithBeanValidationAnnotations(String firstName, String lastName, String email, int age, Sex sex,
            Address address) 

Source Link

Usage

From source file:com.mycompany.vaadinviews.FieldBinderWithBeanValidation.java

public FieldBinderWithBeanValidation() {
    //addComponent(log);
    //this./*from  www.  j  a v  a 2  s .c om*/
    //getContent().
    Layout layout = new VerticalLayout();
    final BeanFieldGroup<PersonWithBeanValidationAnnotations> fieldGroup = new BeanFieldGroup<PersonWithBeanValidationAnnotations>(
            PersonWithBeanValidationAnnotations.class);

    fieldGroup.buildAndBindMemberFields(this);
    //fieldGroup.
    //Layout hlayout = new HorizontalLayout();
    layout.addComponent(firstName);
    //layout.addComponent(hlayout);
    layout.addComponent(lastName);
    layout.addComponent(email);
    layout.addComponent(age);
    layout.addComponent(sex);
    layout.addComponent(deceased);

    Button commitButton = new Button("Commit", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            String msg = "Commit succesful";
            try {
                fieldGroup.commit();
            } catch (CommitException e) {
                msg = "Commit failed: " + e.getMessage();
            }
            Notification.show(msg);
            //log.log(msg);
        }
    });

    Button discardButton = new Button("Discard", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            fieldGroup.discard();
            //log.log("Discarded changes");

        }
    });
    Button showBean = new Button("Show bean values", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show(getPerson(fieldGroup).toString());

        }
    });
    layout.addComponent(commitButton);
    layout.addComponent(discardButton);
    layout.addComponent(showBean);
    sex.setPageLength(0);

    PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations("John", "Doe",
            "john@doe.com", 64, Sex.MALE, new Address("John street", 11223, "John's town", Country.USA));
    fieldGroup.setItemDataSource(new BeanItem<PersonWithBeanValidationAnnotations>(p));
    setContent(layout);
}