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);
}
}
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);
}
}
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)));
}
}
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)));
}
}
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)));
}
}
Aggregations