Class SizeValidator<T>
java.lang.Object
io.jmix.flowui.component.validation.AbstractValidator<T>
io.jmix.flowui.component.validation.SizeValidator<T>
- Type Parameters:
T
- Collection or String
- All Implemented Interfaces:
Validator<T>
,Consumer<T>
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
@Component("flowui_SizeValidator")
@Scope("prototype")
public class SizeValidator<T>
extends AbstractValidator<T>
implements org.springframework.beans.factory.InitializingBean
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("flowui_SizeValidator") @Scope(BeanDefinition.SCOPE_PROTOTYPE) @Primary protected SizeValidator sizeValidator() { return new CustomSizeValidator(); }
-
Field Summary
Fields inherited from class io.jmix.flowui.component.validation.AbstractValidator
applicationContext, currentAuthentication, datatypeRegistry, defaultMessage, message, messages, substitutor
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks a value.protected void
checkPositiveValue
(long value, String message) protected void
checkRange
(int min, int max) int
getMax()
int
getMin()
void
setMax
(int max) Sets max value of the range.void
setMin
(int min) Sets min value of the range.void
setSize
(int min, int max) Sets min and max range values.Methods inherited from class io.jmix.flowui.component.validation.AbstractValidator
afterPropertiesSet, fireValidationException, fireValidationException, formatValue, getMessage, getTemplateErrorMessage, setApplicationContext, setMessage
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
-
Field Details
-
min
protected int min -
max
protected int max
-
-
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
-
setMin
public void setMin(int min) 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
public void setMax(int max) 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:Validator
Checks a value. -
checkPositiveValue
-
checkRange
protected void checkRange(int min, int max)
-