Class GroovyScriptValidator<T>

java.lang.Object
io.jmix.flowui.component.validation.AbstractValidator<T>
io.jmix.dynattrflowui.impl.GroovyScriptValidator<T>
Type Parameters:
T - any Object
All Implemented Interfaces:
Validator<T>, Consumer<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

@Component("dynat_GroovyScriptValidator") @Scope("prototype") public class GroovyScriptValidator<T> extends AbstractValidator<T>
GroovyScript validator runs a custom Groovy script. If the script returns any object, then ValidationException is thrown. scriptResult.toString() is used as error message.

For error message it uses template string and it is possible to use '${value}' key for formatted output.

In order to provide your own implementation globally, create a subclass and register it in configuration class, for example:

     @Bean("dynattr_GroovyScriptValidator")
     @Scope(BeanDefinition.SCOPE_PROTOTYPE)
     @Primary
     protected GroovyScriptValidator groovyScriptValidator() {
          return new CustomGroovyScriptValidator();
     }
 
  • Field Details

    • validatorGroovyScript

      protected String validatorGroovyScript
    • scriptEvaluator

      protected final org.springframework.scripting.ScriptEvaluator scriptEvaluator
  • Constructor Details

  • Method Details

    • 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)
    • setValidatorGroovyScript

      public void setValidatorGroovyScript(String validatorGroovyScript)
      Sets a Groovy script
      Parameters:
      validatorGroovyScript - Groovy script