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
FieldsModifier and TypeFieldDescriptionprotected org.springframework.scripting.ScriptEvaluatorprotected StringFields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor -
Constructor Summary
ConstructorsConstructorDescriptionGroovyScriptValidator(String validatorGroovyScript) Constructor with default error message. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks a value.protected voidfireValidationException(T value) voidsetCurrentAuthentication(CurrentAuthentication currentAuthentication) protected voidsetDatatypeRegistry(DatatypeRegistry datatypeRegistry) protected voidsetMessages(Messages messages) protected voidsetScriptEvaluator(org.springframework.scripting.ScriptEvaluator scriptEvaluator) voidsetStringSubstitutor(StringSubstitutor substitutor) voidsetValidatorGroovyScript(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:ValidatorChecks a value.- Parameters:
value- a value- Throws:
ValidationException
-
fireValidationException
-