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

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

Introduction

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

Prototype

public Address(String streetAddress, int postalCode, String city, Country country) 

Source Link

Usage

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

public FieldBinderWithBeanValidation() {
    //addComponent(log);
    //this./*from www . ja  v a  2  s.c o  m*/
    //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);
}