Package io.jmix.dynattrui.impl
Class GroovyScriptValidator<T>
java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<T>
io.jmix.dynattrui.impl.GroovyScriptValidator<T>
- Type Parameters:
T
- any Object
@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 org.springframework.scripting.ScriptEvaluator
protected String
Fields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor
-
Constructor Summary
ConstructorDescriptionGroovyScriptValidator
(String validatorGroovyScript) Constructor with default error message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks a value.protected void
fireValidationException
(T value) void
setCurrentAuthentication
(CurrentAuthentication currentAuthentication) protected void
setDatatypeRegistry
(DatatypeRegistry datatypeRegistry) protected void
setMessages
(Messages messages) protected void
setScriptEvaluator
(org.springframework.scripting.ScriptEvaluator scriptEvaluator) void
setStringSubstitutor
(StringSubstitutor substitutor) void
setValidatorGroovyScript
(String validatorGroovyScript) Sets a Groovy scriptMethods inherited from class io.jmix.ui.component.validation.AbstractValidator
formatValue, getMessage, getTemplateErrorMessage, setMessage
-
Field Details
-
validatorGroovyScript
-
scriptEvaluator
protected org.springframework.scripting.ScriptEvaluator scriptEvaluator
-
-
Constructor Details
-
GroovyScriptValidator
public GroovyScriptValidator() -
GroovyScriptValidator
Constructor with default error message.- Parameters:
validatorGroovyScript
- groovy script with 'value' macro
-
-
Method Details
-
setMessages
-
setDatatypeRegistry
-
setCurrentAuthentication
-
setStringSubstitutor
-
setScriptEvaluator
@Autowired protected void setScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator) -
getValidatorGroovyScript
- Returns:
- a Groovy script
-
setValidatorGroovyScript
Sets a Groovy script- Parameters:
validatorGroovyScript
- Groovy script
-
accept
Description copied from interface:Validator
Checks a value.- Parameters:
value
- a value- Throws:
ValidationException
-
fireValidationException
-