Search in sources :

Example 1 with ValidationException

use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.

the class PastOrPresentValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }
    TimeValidator timeConstraint = ValidatorHelper.getTimeConstraint(timeSource, value);
    if (timeConstraint == null) {
        throw new IllegalArgumentException("PastOrPresentValidator doesn't support following type: '" + value.getClass() + "'");
    }
    timeConstraint.setCheckSeconds(checkSeconds);
    if (!timeConstraint.isPastOrPresent()) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.pastOrPresent");
        }
        throw new ValidationException(message);
    }
}
Also used : ValidationException(io.jmix.ui.component.ValidationException) TimeValidator(io.jmix.ui.component.validation.time.TimeValidator)

Example 2 with ValidationException

use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.

the class PastValidator method accept.

@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }
    TimeValidator timeConstraint = ValidatorHelper.getTimeConstraint(timeSource, value);
    if (timeConstraint == null) {
        throw new IllegalArgumentException("PastValidator doesn't support following type: '" + value.getClass() + "'");
    }
    timeConstraint.setCheckSeconds(checkSeconds);
    if (!timeConstraint.isPast()) {
        String message = getMessage();
        if (message == null) {
            message = messages.getMessage("validation.constraints.past");
        }
        throw new ValidationException(message);
    }
}
Also used : ValidationException(io.jmix.ui.component.ValidationException) TimeValidator(io.jmix.ui.component.validation.time.TimeValidator)

Example 3 with ValidationException

use of io.jmix.ui.component.ValidationException 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 4 with ValidationException

use of io.jmix.ui.component.ValidationException 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 5 with ValidationException

use of io.jmix.ui.component.ValidationException 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)

Aggregations

ValidationException (io.jmix.ui.component.ValidationException)17 ValidatorHelper.getNumberConstraint (io.jmix.ui.component.validation.ValidatorHelper.getNumberConstraint)6 NumberConstraint (io.jmix.ui.component.validation.number.NumberConstraint)6 CurrentAuthentication (io.jmix.core.security.CurrentAuthentication)4 TimeValidator (io.jmix.ui.component.validation.time.TimeValidator)4 ParseException (java.text.ParseException)4 ServerInfoService (com.haulmont.cuba.core.app.ServerInfoService)1 Messages (com.haulmont.cuba.core.global.Messages)1 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 CronSequenceGenerator (org.springframework.scheduling.support.CronSequenceGenerator)1 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)1 StaticScriptSource (org.springframework.scripting.support.StaticScriptSource)1