Annotation Type ApplicableIf


  • @Documented
    @Target(FIELD)
    @Retention(RUNTIME)
    public @interface 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
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      ApplicableIf.Connection connection
      Defines how multiple expressions in value() are combined.
      String[] value
      The expressions that determine whether the annotated field is applicable.
      • value

        String[] value
        The expressions that determine whether the annotated field is applicable. Must be an EL expression that evaluates to a boolean value. Uses ElEvaluators.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 field
        • values - refers to the instances of the classes containing this field. values[0] is the same as value. 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 to ApplicableIf.Connection.OR.

        Defaults to an empty array, which means the field is always applicable.

        Returns:
        The expression to check.
        Default:
        {}