Example usage for com.vaadin.data Binder getBean

List of usage examples for com.vaadin.data Binder getBean

Introduction

In this page you can find the example usage for com.vaadin.data Binder getBean.

Prototype

public BEAN getBean() 

Source Link

Document

Returns the bean that has been bound with #bind , or null if a bean is not currently bound.

Usage

From source file:org.jpos.qi.minigl.NewEntryForm.java

License:Open Source License

private Button.ClickListener addEntryClickListener(Binder binder) {
    return event -> {
        if (binder.validate().isOk()) {
            if (binder.writeBeanIfValid(binder.getBean())) {
                GLEntry entry = (GLEntry) binder.getBean();
                int count = 0;
                List<GLEntry> newEntriesList = new ArrayList<>();
                for (GLEntry e : transaction.getEntries()) {
                    e.setId(count);/*  w  ww .  j  av  a 2s.c  om*/
                    newEntriesList.add(e);
                    count++;
                }
                if (entry.isCredit()) {
                    GLCredit credit = new GLCredit();
                    credit.setAccount(entry.getAccount());
                    credit.setAmount(entry.getAmount());
                    credit.setLayer(entry.getLayer());
                    credit.setDetail(entry.getDetail());
                    credit.setTags(entry.getTags());
                    credit.setTransaction(entry.getTransaction());
                    credit.setId(count);
                    newEntriesList.add(credit);
                } else if (entry.isDebit()) {
                    GLDebit debit = new GLDebit();
                    debit.setAccount(entry.getAccount());
                    debit.setAmount(entry.getAmount());
                    debit.setLayer(entry.getLayer());
                    debit.setDetail(entry.getDetail());
                    debit.setTags(entry.getTags());
                    debit.setTransaction(entry.getTransaction());
                    debit.setId(count);
                    newEntriesList.add(debit);
                }
                transaction.setEntries(newEntriesList);
                entryGrid.setValue(transaction);
                clearFields();
                shouldReverse = true;
                entryGrid.setComponentError(null);
            }
        } else {
            BindingValidationStatus<?> result = (BindingValidationStatus<?>) binder.validate()
                    .getFieldValidationErrors().get(0);
            app.displayNotification(result.getResult().get().getErrorMessage());
        }
        focusOnFirstField();
    };
}