Top Description Inners Methods
org.hibernate.validator.constraints

public @Interface ParameterScriptAssert

extends Annotation
Annotations
@Documented
@Constraint
validatedBy:
@Target:CONSTRUCTOR, METHOD
@Retention:RUNTIME
@Repeatable:List
Static Imports
java.lang.annotation.ElementType.CONSTRUCTOR, .ElementType.METHOD, .RetentionPolicy.RUNTIME

A method-level constraint, that evaluates a script expression against the annotated method or constructor. This constraint can be used to implement validation routines that depend on several parameters of the annotated executable.

Script expressions can be written in any scripting or expression language, for which a JSR 223 ("Scripting for the JavaTM Platform") compatible engine can be found on the classpath. To refer to a parameter within the scripting expression, use its name as obtained by the active jakarta.validation.ParameterNameProvider. The default provider will return the actual parameter names, if the -parameters compiler option has been enabled, and arg0, arg1 etc. otherwise.

The following listing shows an example using the JavaScript engine which comes with the JDK:

@ParameterScriptAssert(script = "start.before(end)", lang = "javascript")
public void createEvent(Date start, Date end) { ... }

Can be specified on any method or constructor.

Author
Gunnar Morling

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
ParameterScriptAssert.List

Defines several ParameterScriptAssert annotations on the same executable.

Method Summary

Modifier and TypeMethod and Description
public Class<?>[]
public String

Returns:

The name of the script language used by this constraint as expected by the JSR 223 javax.script.ScriptEngineManager. A jakarta.validation.ConstraintDeclarationException will be thrown upon script evaluation, if no engine for the given language could be found.
lang
()

public String
public Class<? extends Payload>[]
public String

Returns:

The script to be executed. The script must return Boolean.TRUE, if the executable parameters could successfully be validated, otherwise Boolean.FALSE. Returning null or any type other than Boolean will cause a jakarta.validation.ConstraintDeclarationException upon validation. Any exception occurring during script evaluation will be wrapped into a ConstraintDeclarationException, too. Within the script, the validated parameters can be accessed using their names as retrieved from the active jakarta.validation.ParameterNameProvider.
script
()

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

groupsback to summary
public Class<?>[] groups()
langback to summary
public String lang()
Returns:String

The name of the script language used by this constraint as expected by the JSR 223 javax.script.ScriptEngineManager. A jakarta.validation.ConstraintDeclarationException will be thrown upon script evaluation, if no engine for the given language could be found.

messageback to summary
public String message()
payloadback to summary
public Class<? extends Payload>[] payload()
scriptback to summary
public String script()
Returns:String

The script to be executed. The script must return Boolean.TRUE, if the executable parameters could successfully be validated, otherwise Boolean.FALSE. Returning null or any type other than Boolean will cause a jakarta.validation.ConstraintDeclarationException upon validation. Any exception occurring during script evaluation will be wrapped into a ConstraintDeclarationException, too. Within the script, the validated parameters can be accessed using their names as retrieved from the active jakarta.validation.ParameterNameProvider.

org.hibernate.validator.constraints back to summary

public @Interface ParameterScriptAssert.List

extends Annotation
Annotations
@Target:CONSTRUCTOR, METHOD
@Retention:RUNTIME
@Documented

Defines several ParameterScriptAssert annotations on the same executable.

Method Summary

Modifier and TypeMethod and Description
public ParameterScriptAssert[]
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public ParameterScriptAssert[] value()