Skip to content

@DependsOn

The @DependsOn annotation creates cascading dependencies between fields. When field A depends on field B, the UI will filter the available values of field A based on the current value of field B (cascading dropdowns).

Basic Usage

java
@Entity
@SquizyEntity
public class Address {

    @ManyToOne(optional = false)
    @NotNull
    private Country country;

    @DependsOn("country")
    @ManyToOne(optional = false)
    @NotNull
    private State state;

    @DependsOn("state")
    @ManyToOne(optional = false)
    @NotNull
    private City city;
}

In this example:

  • Selecting a country filters the available states
  • Selecting a state filters the available cities

How It Works

When a field depends on another field, the UI enforces the dependency visually and functionally:

  1. While the dependency field has no value, the dependent field is disabled — the user cannot interact with it or select a value.
  2. Once the dependency field is set, the dependent field becomes enabled and its available values are filtered based on the dependency value.

When the UI queries the available values for a dependent field, it passes the current value of the dependency field as an additional filter criterion. By default:

  • For singular dependency fields (@ManyToOne), the EQ (equals) operator is used
  • For plural dependency fields (collections), the IN operator is used

The filter is applied automatically to the property query for the dependent field.

Attributes

value

The name of the field this field depends on:

java
@DependsOn("country")
private State state;

modes

Controls in which UI modes the dependency is active:

java
@DependsOn(value = "country", modes = { Mode.CREATION })
private State state;

Available modes: CREATION, EDITION. Defaults to both.

operator

Overrides the query operator used for filtering:

java
@DependsOn(value = "region", operator = QueryOperator.IN)
private State state;

Default: EQ for singular fields, IN for plural fields.

filterField

Specifies which field of the dependent entity should be matched against the dependency value. If not specified, the same field name as value is used:

java
@DependsOn(value = "country", filterField = "countryOfOrigin")
private State state;

manualMode

When true, the automatic filtering is disabled and the dependency is handled by a custom implementation:

java
@DependsOn(value = "country", manualMode = true)
private State state;

Multiple Dependencies

A field can depend on multiple fields using repeatable annotations:

java
@DependsOn("country")
@DependsOn("type")
@ManyToOne
private Region region;