Class GroovyScriptValidator<T>

java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.dynattrui.impl.GroovyScriptValidator<T>
Type Parameters:
T - any Object
All Implemented Interfaces:
Validator<T>, Consumer<T>

@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 org.springframework.scripting.ScriptEvaluator scriptEvaluator
  • Constructor Details

    • GroovyScriptValidator

      public GroovyScriptValidator()
    • GroovyScriptValidator

      public GroovyScriptValidator(String validatorGroovyScript)
      Constructor with default error message.
      Parameters:
      validatorGroovyScript - groovy script with 'value' macro
  • Method Details

    • setMessages

      @Autowired protected void setMessages(Messages messages)
    • setDatatypeRegistry

      @Autowired protected void setDatatypeRegistry(DatatypeRegistry datatypeRegistry)
    • setCurrentAuthentication

      @Autowired public void setCurrentAuthentication(CurrentAuthentication currentAuthentication)
    • setStringSubstitutor

      @Autowired public void setStringSubstitutor(StringSubstitutor substitutor)
    • setScriptEvaluator

      @Autowired protected void setScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator)
    • getValidatorGroovyScript

      public String getValidatorGroovyScript()
      Returns:
      a Groovy script
    • setValidatorGroovyScript

      public void setValidatorGroovyScript(String validatorGroovyScript)
      Sets a Groovy script
      Parameters:
      validatorGroovyScript - Groovy script
    • 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)