Example usage for com.vaadin.data Binder validate

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

Introduction

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

Prototype

public BinderValidationStatus<BEAN> validate() 

Source Link

Document

Validates the values of all bound fields and returns the validation status.

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);//from  ww w . j a  v a 2 s.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();
    };
}