Search in sources :

Example 16 with ValidationException

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

Example 17 with ValidationException

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