Example usage for com.vaadin.data.validator BigDecimalRangeValidator BigDecimalRangeValidator

List of usage examples for com.vaadin.data.validator BigDecimalRangeValidator BigDecimalRangeValidator

Introduction

In this page you can find the example usage for com.vaadin.data.validator BigDecimalRangeValidator BigDecimalRangeValidator.

Prototype

public BigDecimalRangeValidator(String errorMessage, BigDecimal minValue, BigDecimal maxValue) 

Source Link

Document

Creates a validator for checking that an BigDecimal is within a given range.

Usage

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

License:Open Source License

private void createAndBindFields(Binder binder) {
    TextField accountCode = createTextField("accountCode");
    ComboBox layer = createLayersSelector();
    TextField detail = createTextField("detail");
    TextField tags = createTextField("tags");
    TextField amount = createTextField("amount");
    RadioButtonGroup credit = createCreditOrDebit();
    binder.forField(accountCode).withNullRepresentation("").withConverter(new AccountConverter())
            .withValidator((Validator<Account>) (value, context) -> {
                if (value != null && !(value instanceof FinalAccount))
                    return ValidationResult.error(app.getMessage("errorMessage.accountNotFinal"));
                else if (value == null)
                    return ValidationResult.error(app.getMessage("errorMessage.req",
                            StringUtils.capitalize(accountCode.getCaption())));
                return ValidationResult.ok();
            }).asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(layer.getCaption())))
            .bind("account");
    binder.forField(layer).withConverter(new ShortToLayerConverter(journal))
            .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(layer.getCaption())))
            .bind("layer");
    binder.forField(detail)//from w w w .j av  a 2s  . c  o m
            .withValidator(new StringLengthValidator(
                    app.getMessage("errorMessage.invalidField", detail.getCaption()), 0, 255))
            .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", detail.getCaption()),
                    TEXT_REGEX))
            .bind("detail");
    binder.forField(tags)
            .withValidator(new StringLengthValidator(
                    app.getMessage("errorMessage.invalidField", tags.getCaption()), 0, 255))
            .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", tags.getCaption()),
                    TEXT_REGEX))
            .withConverter(new StringToTagConverter()).bind("tags");
    binder.forField(amount)
            .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(amount.getCaption())))
            .withConverter(new StringToBigDecimalConverter(app.getMessage("errorMessage.invalidAmount")))
            .withValidator(new BigDecimalRangeValidator(app.getMessage("errorMessage.invalidAmount"),
                    new BigDecimal("1"), new BigDecimal("99999999999999")))
            .withNullRepresentation(BigDecimal.ZERO).bind("amount");
    binder.bind(credit, "credit");
    addComponent(accountCode);
    addComponent(layer);
    addComponent(detail);
    addComponent(tags);
    addComponent(amount);
    addComponent(credit);
    setComponentAlignment(credit, Alignment.BOTTOM_CENTER);
}