Search in sources :

Example 6 with NumberConstraint

use of io.jmix.ui.component.validation.number.NumberConstraint in project jmix by jmix-framework.

the class PositiveValidator method accept.

@Override
public void accept(T value) {
    // consider null is valid
    if (value == null) {
        return;
    }
    NumberConstraint constraint = getNumberConstraint(value);
    if (constraint == null) {
        throw new IllegalArgumentException("PositiveValidator doesn't support following type: '" + value.getClass() + "'");
    }
    if (!constraint.isPositive()) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.positive");
        }
        String formattedValue = formatValue(value);
        throw new ValidationException(getTemplateErrorMessage(message, ParamsMap.of("value", formattedValue)));
    }
}
Also used : NumberConstraint(io.jmix.ui.component.validation.number.NumberConstraint) ValidatorHelper.getNumberConstraint(io.jmix.ui.component.validation.ValidatorHelper.getNumberConstraint) ValidationException(io.jmix.ui.component.ValidationException)

Aggregations

ValidationException (io.jmix.ui.component.ValidationException)6 ValidatorHelper.getNumberConstraint (io.jmix.ui.component.validation.ValidatorHelper.getNumberConstraint)6 NumberConstraint (io.jmix.ui.component.validation.number.NumberConstraint)6