T
- Collection or String@Scope(value="prototype") @Component(value="cuba_SizeValidator") public class SizeValidator<T> extends AbstractValidator<T>
For error message it uses Groovy 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 web-spring.xml
,
for example:
<bean id="cuba_SizeValidator" class="com.haulmont.cuba.gui.components.validation.SizeValidator" scope="prototype"/>Use
BeanLocator
when creating the validator programmatically.Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
defaultMessage |
protected int |
max |
protected int |
min |
static java.lang.String |
NAME |
datatypeRegistry, message, messages, userSessionSource
Constructor and Description |
---|
SizeValidator() |
SizeValidator(java.lang.String message)
Constructor for custom error message.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(T 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(Messages messages) |
void |
setMin(int min)
Sets min value of the range.
|
void |
setSize(int min,
int max)
Sets min and max range values.
|
formatValue, getMessage, getTemplateErrorMessage, setMessage
public static final java.lang.String NAME
protected 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@Inject protected void setMessages(Messages messages)
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()
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
ValidationException
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)