Class SizeValidator<T>

java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.ui.component.validation.SizeValidator<T>
Type Parameters:
T - Collection or String
All Implemented Interfaces:
Validator<T>, Consumer<T>

@Scope("prototype") @Component("ui_SizeValidator") public class SizeValidator<T> extends AbstractValidator<T>
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("ui_SizeValidator")
     @Scope(BeanDefinition.SCOPE_PROTOTYPE)
     @Primary
     protected SizeValidator sizeValidator() {
          return new CustomSizeValidator();
     }
 
  • Field Details

    • min

      protected int min
    • max

      protected int max
    • defaultMessage

      protected String defaultMessage
  • Constructor Details

    • SizeValidator

      public SizeValidator()
    • SizeValidator

      public SizeValidator(String message)
      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

    • setMessages

      @Autowired protected void setMessages(Messages messages)
    • setStringSubstitutor

      @Autowired public void setStringSubstitutor(StringSubstitutor substitutor)
    • setMin

      @StudioProperty 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

      @StudioProperty public void setMax(int max)
      Sets max value of the range. Max value cannot be less than 0. Default value is Integer.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 value
      max - max value
    • accept

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

      protected void checkPositiveValue(long value, String message)
    • checkRange

      protected void checkRange(int min, int max)
    • fireValidationException

      protected void fireValidationException(String errorMessage, Map<String,Object> map)