Package io.jmix.dynattrflowui.impl
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 Summary
Modifier and TypeFieldDescriptionprotected final org.springframework.scripting.ScriptEvaluator
protected String
Fields inherited from class io.jmix.flowui.component.validation.AbstractValidator
applicationContext, currentAuthentication, datatypeRegistry, defaultMessage, message, messages, substitutor
-
Constructor Summary
ConstructorDescriptionGroovyScriptValidator
(Messages messages, DatatypeRegistry datatypeRegistry, CurrentAuthentication currentAuthentication, StringSubstitutor substitutor, org.springframework.scripting.ScriptEvaluator scriptEvaluator) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks a value.protected void
fireValidationException
(T value) void
setValidatorGroovyScript
(String validatorGroovyScript) Sets a Groovy scriptMethods inherited from class io.jmix.flowui.component.validation.AbstractValidator
afterPropertiesSet, fireValidationException, fireValidationException, formatValue, getMessage, getTemplateErrorMessage, setApplicationContext, setMessage
-
Field Details
-
validatorGroovyScript
-
scriptEvaluator
protected final org.springframework.scripting.ScriptEvaluator scriptEvaluator
-
-
Constructor Details
-
GroovyScriptValidator
public GroovyScriptValidator(Messages messages, DatatypeRegistry datatypeRegistry, CurrentAuthentication currentAuthentication, StringSubstitutor substitutor, org.springframework.scripting.ScriptEvaluator scriptEvaluator)
-
-
Method Details
-
accept
Description copied from interface:Validator
Checks a value.- Parameters:
value
- a value- Throws:
ValidationException
-
fireValidationException
-
setValidatorGroovyScript
Sets a Groovy script- Parameters:
validatorGroovyScript
- Groovy script
-