Package io.jmix.ui.component.validation
Class DecimalMaxValidator<T>
java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.ui.component.validation.DecimalMaxValidator<T>
- Type Parameters:
T- BigDecimal, BigInteger, Long, Integer and String that represents BigDecimal value with current locale
@Component("ui_DecimalMaxValidator")
@Scope("prototype")
public class DecimalMaxValidator<T>
extends AbstractValidator<T>
DecimalMax validator checks that value must be less than or equal to the specified maximum.
For error message it uses template string and it is possible to use '${value}' and '${max}' keys for formatted output.
In order to provide your own implementation globally, create a subclass and register it in configuration class, for example:
@Bean("ui_DecimalMaxValidator")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Primary
protected DecimalMaxValidator decimalMaxValidator(BigDecimal max) {
return new CustomDecimalMaxValidator(max);
}
-
Field Summary
FieldsFields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default error message.DecimalMaxValidator(BigDecimal max, String message) Constructor with custom error message. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks a value.protected voidfireValidationException(T value) protected StringgetMax()booleanvoidsetCurrentAuthentication(CurrentAuthentication currentAuthentication) protected voidsetDatatypeRegistry(DatatypeRegistry datatypeRegistry) voidsetInclusive(boolean inclusive) Set to true if the value must be less than or equal to the specified maximum.voidsetMax(BigDecimal max) Sets max value.voidsetMax(BigDecimal max, boolean inclusive) Sets max value and inclusive option.protected voidsetMessages(Messages messages) voidsetStringSubstitutor(StringSubstitutor substitutor) Methods inherited from class io.jmix.ui.component.validation.AbstractValidator
formatValue, getMessage, getTemplateErrorMessage, setMessage
-
Field Details
-
max
-
inclusive
protected boolean inclusive
-
-
Constructor Details
-
DecimalMaxValidator
Constructor with default error message.- Parameters:
max- max value
-
DecimalMaxValidator
Constructor with custom error message. This message can contain '${value}', and '${max}' keys for formatted output.Example: "Value '${value}' should be less than or equal to '${max}'".
- Parameters:
max- max valuemessage- error message
-
-
Method Details
-
setMessages
-
setDatatypeRegistry
-
setCurrentAuthentication
-
setStringSubstitutor
-
setMax
Sets max value.- Parameters:
max- max value
-
getMax
- Returns:
- max value
-
setMax
Sets max value and inclusive option.- Parameters:
max- max valueinclusive- inclusive option
-
setInclusive
Set to true if the value must be less than or equal to the specified maximum. Default value is true.- Parameters:
inclusive- inclusive option
-
isInclusive
public boolean isInclusive()- Returns:
- true if the value must be less than or equal to the specified maximum
-
accept
Description copied from interface:ValidatorChecks a value.- Parameters:
value- a value- Throws:
ValidationException
-
getDefaultMessage
-
fireValidationException
-