Package io.jmix.ui.component.validation
Class SizeValidator<T>
java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.ui.component.validation.SizeValidator<T>
- Type Parameters:
T- Collection or String
@Scope("prototype")
@Component("ui_SizeValidator")
public class SizeValidator<T>
extends AbstractValidator<T>
Size validator is applicable for Collections and String values. It checks that value is in a specific range.
For error message it uses template string and it is possible to use following keys for formatted output: '${value}', '${min}' and '${max}'.
Note, that size validator for Collection doesn't use key '${value}' for output error message.
In order to provide your own implementation globally, create a subclass and register it in configuration class, for example:
@Bean("ui_SizeValidator")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Primary
protected SizeValidator sizeValidator() {
return new CustomSizeValidator();
}
-
Field Summary
FieldsFields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks a value.protected voidcheckPositiveValue(long value, String message) protected voidcheckRange(int min, int max) protected voidfireValidationException(String errorMessage, Map<String, Object> map) intgetMax()intgetMin()voidsetMax(int max) Sets max value of the range.protected voidsetMessages(Messages messages) voidsetMin(int min) Sets min value of the range.voidsetSize(int min, int max) Sets min and max range values.voidsetStringSubstitutor(StringSubstitutor substitutor) Methods inherited from class io.jmix.ui.component.validation.AbstractValidator
formatValue, getMessage, getTemplateErrorMessage, setMessage
-
Field Details
-
min
protected int min -
max
protected int max -
defaultMessage
-
-
Constructor Details
-
SizeValidator
public SizeValidator() -
SizeValidator
Constructor for custom error message. This message can contain following keys formatted output: '${value}', '${min}', and '${max}'.Example: "The '${value}' length must be between '${min}' and '${max}'".
Note, that message for Collection doesn't use '${value}' key for output error message.
- Parameters:
message- error message
-
-
Method Details
-
setMessages
-
setStringSubstitutor
-
setMin
Sets min value of the range. Min value cannot be less than 0. Default value is 0.Note, min value is included in range. Examples:
value = 0, min = 0 - is valid value = 1, min = 2 - is not valid- Parameters:
min- min value
-
getMin
public int getMin() -
setMax
Sets max value of the range. Max value cannot be less than 0. Default value isInteger.MAX_VALUE.Note, max value is included in range. Examples:
value = 5, max = 5 - is valid value = 6, max = 5 - is not valid- Parameters:
max- max value
-
getMax
public int getMax()- Returns:
- max value of the range
-
setSize
public void setSize(int min, int max) Sets min and max range values. Min and max values cannot be less than 0.- Parameters:
min- min valuemax- max value
-
accept
Description copied from interface:ValidatorChecks a value.- Parameters:
value- a value- Throws:
ValidationException
-
checkPositiveValue
-
checkRange
protected void checkRange(int min, int max) -
fireValidationException
-