Class VisibilityRule

java.lang.Object
org.apache.juneau.console.views.VisibilityRule

@BeanType(properties="field,op,value") public final class VisibilityRule extends Object
A presentation-only visibility rule: the element is shown only when every rule in its list matches.

Rules hide UI; they never authorize. The endpoint behind a hidden action must still check the caller. Use visible(false) instead when the element must not reach the client at all.

The evaluation map depends on the element's level. A row action, detail field or region sees the row plus the page's facts under a facts. prefix; a card, badge or ribbon item sees the page's top-level facts alone. A field absent from the map fails closed for every operator except absent.

Example:

RowAction.create("escalate") .visibleWhen( VisibilityRule.when("status").in("open", "acked"), VisibilityRule.when("facts.viewer.roles").contains("oncall"));

Since:
10.0.0
  • Field Details

    • field

      public String field
      The field this rule tests, a dotted path into the evaluation map (e.g. "facts.viewer.roles").
    • op

      public String op
      The wire token of the comparison operator (see Op.wire()).
    • value

      public Object value
      The comparison value for eq/ne/in/contains; omitted for present/absent.
  • Method Details

    • when

      public static VisibilityRule.Builder when(String field)
      Starts a rule for the given field.
      Parameters:
      field - The dotted-path field to test. Must not be null or blank.
      Returns:
      A VisibilityRule.Builder to pick the operator.
      Throws:
      IllegalArgumentException - If field is null or blank.
    • test

      public static boolean test(List<VisibilityRule> rules, Map<String,Object> map)
      Evaluates a list of rules against an evaluation map; every rule must match (AND).

      A null or empty list always matches. A field absent from map never satisfies eq/ne/in/contains/present; only absent treats a missing field as a match. Mirrors the JS JuneauViews.rules.test evaluator exactly.

      Parameters:
      rules - The rules to test, or null.
      map - The evaluation map.
      Returns:
      true when every rule matches.
      Throws:
      IllegalArgumentException - If a rule's op is not one of the known tokens.
    • toMap

      public Map<String,Object> toMap()
      Serializes this rule to its wire shape.
      Returns:
      An ordered Map of field, op and (when set) value.