Search in sources :

Example 1 with NumberConstraint

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

the class PositiveOrZeroValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null is valid
    if (value == null) {
        return;
    }
    NumberConstraint constraint = getNumberConstraint(value);
    if (constraint == null) {
        throw new IllegalArgumentException("PositiveOrZeroValidator doesn't support following type: '" + value.getClass() + "'");
    }
    if (!constraint.isPositiveOrZero()) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.positiveOrZero");
        }
        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)

Example 2 with NumberConstraint

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

the class MaxValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }
    NumberConstraint constraint = getNumberConstraint(value);
    if (constraint == null || value instanceof Double || value instanceof Float) {
        throw new IllegalArgumentException("MaxValidator doesn't support following type: '" + value.getClass() + "'");
    }
    if (!constraint.isMax(max)) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.max");
        }
        String formattedValue = formatValue(value);
        String formattedMax = formatValue(max);
        throw new ValidationException(getTemplateErrorMessage(message, ParamsMap.of("value", formattedValue, "max", formattedMax)));
    }
}
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)

Example 3 with NumberConstraint

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

the class NegativeOrZeroValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }
    NumberConstraint constraint = getNumberConstraint(value);
    if (constraint == null) {
        throw new IllegalArgumentException("NegativeOrZeroValidator doesn't support following type: '" + value.getClass() + "'");
    }
    if (!constraint.isNegativeOrZero()) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.negativeOrZero");
        }
        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)

Example 4 with NumberConstraint

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

the class MinValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }
    NumberConstraint constraint = getNumberConstraint(value);
    if (constraint == null || value instanceof Double || value instanceof Float) {
        throw new IllegalArgumentException("MinValidator doesn't support following type: '" + value.getClass() + "'");
    }
    if (!constraint.isMin(min)) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.min");
        }
        String formattedValue = formatValue(value);
        String formattedMin = formatValue(min);
        throw new ValidationException(getTemplateErrorMessage(message, ParamsMap.of("value", formattedValue, "min", formattedMin)));
    }
}
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)

Example 5 with NumberConstraint

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

the class NegativeValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }
    NumberConstraint constraint = getNumberConstraint(value);
    if (constraint == null) {
        throw new IllegalArgumentException("NegativeValidator doesn't support following type: '" + value.getClass() + "'");
    }
    if (!constraint.isNegative()) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.negative");
        }
        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