Package io.jmix.ui.component.validation
Class DigitsValidator<T>
java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.ui.component.validation.DigitsValidator<T>
- Type Parameters:
T
- BigDecimal, BigInteger, Long, Integer and String that represents BigDecimal value with current locale
@Component("ui_DigitsValidator")
@Scope("prototype")
public class DigitsValidator<T>
extends AbstractValidator<T>
Digits validator checks that value must be a number within accepted range.
For error message it uses template string and it is possible to use '${value}', '${integer}' and '${fraction}' 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_DigitsValidator") @Scope(BeanDefinition.SCOPE_PROTOTYPE) @Primary protected DigitsValidator digitsValidator(int integer, int fraction) { return new CustomDigitsValidator(integer, fraction); }
-
Field Summary
Fields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor
-
Constructor Summary
ConstructorDescriptionDigitsValidator
(int integer, int fraction) Constructor with default error message.DigitsValidator
(int integer, int fraction, String message) Constructor with custom error message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks a value.protected void
fireValidationException
(T value) int
int
void
setCurrentAuthentication
(CurrentAuthentication currentAuthentication) protected void
setDatatypeRegistry
(DatatypeRegistry datatypeRegistry) void
setFraction
(int fraction) Sets maximum value inclusive.void
setInteger
(int integer) Sets maximum value inclusive.protected void
setMessages
(Messages messages) void
setStringSubstitutor
(StringSubstitutor substitutor) Methods inherited from class io.jmix.ui.component.validation.AbstractValidator
formatValue, getMessage, getTemplateErrorMessage, setMessage
-
Field Details
-
integer
protected int integer -
fraction
protected int fraction
-
-
Constructor Details
-
DigitsValidator
public DigitsValidator(int integer, int fraction) Constructor with default error message.- Parameters:
integer
- maximum number of integral digitsfraction
- maximum number of fractional digits
-
DigitsValidator
Constructor with custom error message. This message can contain '${value}', '${integer}' and '${fraction}' keys for formatted output.Example: "Value '${value}' is out of bounds ('${integer}' digits is expected in integer part and '${fraction}' in fractional part)".
- Parameters:
integer
- maximum number of integral digitsfraction
- maximum number of fractional digitsmessage
- error message
-
-
Method Details
-
setDatatypeRegistry
-
setCurrentAuthentication
-
setMessages
-
setStringSubstitutor
-
setInteger
Sets maximum value inclusive.- Parameters:
integer
- maximum number of integral digits
-
setFraction
Sets maximum value inclusive.- Parameters:
fraction
- maximum number of fractional digits
-
getInteger
public int getInteger()- Returns:
- maximum number of integral digits
-
getFraction
public int getFraction()- Returns:
- maximum number of fractional digits
-
accept
Description copied from interface:Validator
Checks a value.- Parameters:
value
- a value- Throws:
ValidationException
-
fireValidationException
-