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
All Implemented Interfaces:
Validator<T>, Consumer<T>

@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 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 digits
      fraction - maximum number of fractional digits
    • DigitsValidator

      public DigitsValidator(int integer, int fraction, String message)
      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 digits
      fraction - maximum number of fractional digits
      message - error message
  • Method Details

    • setDatatypeRegistry

      @Autowired protected void setDatatypeRegistry(DatatypeRegistry datatypeRegistry)
    • setCurrentAuthentication

      @Autowired public void setCurrentAuthentication(CurrentAuthentication currentAuthentication)
    • setMessages

      @Autowired protected void setMessages(Messages messages)
    • setStringSubstitutor

      @Autowired public void setStringSubstitutor(StringSubstitutor substitutor)
    • setInteger

      @StudioProperty(required=true) public void setInteger(int integer)
      Sets maximum value inclusive.
      Parameters:
      integer - maximum number of integral digits
    • setFraction

      @StudioProperty(required=true) public void setFraction(int fraction)
      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

      public void accept(T value) throws ValidationException
      Description copied from interface: Validator
      Checks a value.
      Parameters:
      value - a value
      Throws:
      ValidationException
    • fireValidationException

      protected void fireValidationException(T value)