Annotation Type ApplicableIf
Annotation for fields that defines a condition whether the field is applicable or not, by evaluating an EL
expression. A field might not be applicable e.g. when it is disabled, hidden, or not relevant for the current
context. This is a general-purpose annotation that does not define the semantics of what happens when a field is not
applicable -- this depends on the context where a class with this annotation is used.
For example, consider a view model for a customer's address, with boolean flag indicating whether the customer has a separate billing address:
class Address {
private String shippingAddress;
private boolean separateBillingAddress;
@ApplicableIf("value.separateBillingAddress")
private String billingAddress;
}
- Since:
- 8.5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe connection type for combining multiple expressions. -
Optional Element Summary
Optional Elements
-
Element Details
-
connection
ApplicableIf.Connection connectionDefines how multiple expressions invalue()are combined. IfApplicableIf.Connection.ANDis used, all expressions must evaluate to true for the field to be applicable. IfApplicableIf.Connection.ORis used, at least one expression must evaluate to true for the field to be applicable. Default isApplicableIf.Connection.OR.- Returns:
- The connection type.
- Default:
OR
-
value
String[] valueThe expressions that determine whether the annotated field is applicable. Must be an EL expression that evaluates to a boolean value. UsesElEvaluators.standard()for evaluation, see there for more details. The following top-level variables are available:value- refers to the instance of the class containing this fieldvalues- refers to the instances of the classes containing this field.values[0]is the same asvalue.values[1]is the instance containing the value, etc.context- refers to the context in which the evaluation takes place. The exact value depends on where this annotation is used.
If multiple expressions are provided, they are combined according to the
connection()setting, which defaults toApplicableIf.Connection.OR.Defaults to an empty array, which means the field is always applicable.
- Returns:
- The expression to check.
- Default:
{}
-