T - Collection or String@Scope(value="prototype") @Component(value="ui_SizeValidator") public class SizeValidator<T> extends AbstractValidator<T>
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();
}
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
defaultMessage |
protected int |
max |
protected int |
min |
currentAuthentication, datatypeRegistry, message, messages, substitutor| Constructor and Description |
|---|
SizeValidator() |
SizeValidator(java.lang.String message)
Constructor for custom error message.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(T value)
Checks a value.
|
protected void |
checkPositiveValue(long value,
java.lang.String message) |
protected void |
checkRange(int min,
int max) |
protected void |
fireValidationException(java.lang.String errorMessage,
java.util.Map<java.lang.String,java.lang.Object> map) |
int |
getMax() |
int |
getMin() |
void |
setMax(int max)
Sets max value of the range.
|
protected void |
setMessages(io.jmix.core.Messages messages) |
void |
setMin(int min)
Sets min value of the range.
|
void |
setSize(int min,
int max)
Sets min and max range values.
|
void |
setStringSubstitutor(StringSubstitutor substitutor) |
formatValue, getMessage, getTemplateErrorMessage, setMessageprotected int min
protected int max
protected java.lang.String defaultMessage
public SizeValidator()
public SizeValidator(java.lang.String message)
Example: "The '${value}' length must be between '${min}' and '${max}'".
Note, that message for Collection doesn't use '${value}' key for output error message.
message - error message@Autowired protected void setMessages(io.jmix.core.Messages messages)
@Autowired public void setStringSubstitutor(StringSubstitutor substitutor)
@StudioProperty public void setMin(int min)
Note, min value is included in range. Examples:
value = 0, min = 0 - is valid
value = 1, min = 2 - is not valid
min - min valuepublic int getMin()
@StudioProperty public void setMax(int max)
Integer.MAX_VALUE.
Note, max value is included in range. Examples:
value = 5, max = 5 - is valid
value = 6, max = 5 - is not valid
max - max valuepublic int getMax()
public void setSize(int min,
int max)
min - min valuemax - max valuepublic void accept(T value) throws ValidationException
Validatorvalue - a valueValidationExceptionprotected void checkPositiveValue(long value,
java.lang.String message)
protected void checkRange(int min,
int max)
protected void fireValidationException(java.lang.String errorMessage,
java.util.Map<java.lang.String,java.lang.Object> map)