Annotation Type MustNotBeEqualIfOtherHasValue
@Documented
@Constraint(validatedBy=MustNotBeEqualIfOtherHasValueValidator.class)
@Target({TYPE,ANNOTATION_TYPE})
@Retention(RUNTIME)
public @interface MustNotBeEqualIfOtherHasValue
The annotated bean must contain at least two properties:
Supported types are beans,
- a field to compare (option
field1) - another field to compared (option
field2) - a field which entry is compared against a value (option
fieldCompareandvalueCompare) - add the error to field1 (option
addErrorToField1, default true) - add the error to field2 (option
addErrorToField2, default true)
field1 must not be equal to the entry of field2 when the
entry of fieldCompare has the value valueCompare, can be used e.g. for
password old and password new fields.Supported types are beans,
null elements are considered valid.- Author:
- Manfred Tremmel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceDefines severalMustNotBeEqualIfOtherHasValueannotations on the same element. -
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionfield1 name to compare.field2 name to compare.field name to compare.String[]value the compare field must have to check. -
Optional Element Summary
Optional Elements
-
Element Details
-
field1
String field1field1 name to compare.- Returns:
- field/path contains value to compare
-
field2
String field2field2 name to compare.- Returns:
- field/path contains value to compare
-
fieldCompare
String fieldComparefield name to compare.- Returns:
- field/path contains value to compare
-
valueCompare
String[] valueComparevalue the compare field must have to check.- Returns:
- value to compare
-
-
-
message
String messagelocalized message.- Returns:
- localized validation message
- Default:
- "{de.knightsoftnet.validators.shared.MustNotBeEqual.message}"
-
groups
Class<?>[] groupsgroups to use.- Returns:
- array of validation groups
- Default:
- {}
-
addErrorToField1
boolean addErrorToField1add error to field1 (default true).- Returns:
- true if error should be added to field1
- Default:
- true
-
addErrorToField2
boolean addErrorToField2add error to field2 (default true).- Returns:
- true if error should be added to field2
- Default:
- true
-
payload
Class<? extends jakarta.validation.Payload>[] payloadpayload whatever.- Returns:
- payload class
- Default:
- {}
-