Package io.jmix.ui.component.validation
Class MaxValidator<T extends Number>
java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.ui.component.validation.MaxValidator<T>
- Type Parameters:
T- BigDecimal, BigInteger, Long, Integer
@Component("ui_MaxValidator")
@Scope("prototype")
public class MaxValidator<T extends Number>
extends AbstractValidator<T>
Max 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_MaxValidator")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Primary
protected MaxValidator maxValidator(long max) {
return new CustomMaxValidator(max);
}
-
Field Summary
FieldsFields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor -
Constructor Summary
ConstructorsConstructorDescriptionMaxValidator(long max) MaxValidator(long max, String message) Constructor for custom error message. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks a value.longgetMax()voidsetCurrentAuthentication(CurrentAuthentication currentAuthentication) protected voidsetDatatypeRegistry(DatatypeRegistry datatypeRegistry) voidsetMax(long max) Sets max value.protected voidsetMessages(Messages messages) voidsetStringSubstitutor(StringSubstitutor substitutor) Methods inherited from class io.jmix.ui.component.validation.AbstractValidator
formatValue, getMessage, getTemplateErrorMessage, setMessage
-
Field Details
-
max
protected long max
-
-
Constructor Details
-
MaxValidator
public MaxValidator(long max) -
MaxValidator
Constructor for 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
public long getMax()- Returns:
- max value
-
accept
Description copied from interface:ValidatorChecks a value.- Parameters:
value- a value- Throws:
ValidationException
-