Class SelectionDef

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

public final class SelectionDef extends Object
The row-selection opt-in for a ViewTable — the first of the view table's two INDEPENDENT opt-ins.
Independent from bulk mutation, by construction

Declaring a SelectionDef adds a per-row checkbox column (and, when selectAll() is set, a select-all header checkbox) to a view table — nothing else. It does not, by any default or convenience, surface a bulk-mutate control: ViewTable's selection markers (ViewTable.SELECT_ATTR and siblings) have no code path that can render one. A view can therefore declare "selectable, for export" while categorically excluding bulk mutation — e.g. a PagerDuty-style incident table that wants selection for a client-side export/copy action but must never expose a multi-row mutate. A BulkMutateDef is a separate, independent type that consumes a SelectionDef (it requires one to be constructed at all) but a SelectionDef never requires, implies, or references one back.

Non-wire: never touches VIEW_META

A SelectionDef is deliberately not part of VIEW_META and never reaches the JSON sidecar. ViewTable instead stamps it as plain HTML attributes directly on the emitted <table> — ViewTable.SELECT_ATTR, ViewTable.ROW_ID_FIELD_ATTR, ViewTable.SELECT_ALL_ATTR — mirroring the existing ViewTable.CSRF_ATTR auto-embed pattern. The juneau-views.js runtime reads them straight off the DOM, so a table with no SelectionDef carries none of these attributes and renders no selection UI at all; there is no shared, independently-versioned wire contract to keep in lockstep (contrast BulkMutateDef, whose actual bulk-action list is wire data and therefore carries its own, separate BulkMutateDef.CONTRACT_VERSION).

Selection identity is a stable row id, never a DOM/table index

rowIdField() names the row-data key juneau-views.js reads to stamp a stable data-juneau-row-id attribute on each rendered <tr> (see createdRow in that runtime). Selection state is keyed by that value, never by a row's position in the DOM or in the DataTables draw — so a poll refresh, a sort, or a page change can never retarget a selection (or a bulk mutate driven from one) onto whichever rows now occupy those same positions. The runtime's persistence rule drops any previously-selected id that is no longer present in the newly drawn row set, so a selection whose rows have scrolled off screen or off the current page is never kept as a live, actionable target.

Example:

// Selectable for export, with NO bulk-mutate capability - satisfies the separability condition by construction. SelectionDef selection = SelectionDef.create("id") .selectAll(true) .selectableWhen(RowActionEnabledRule.of("state", Op.EQ, "PENDING", "Only pending changes can be aborted.")) .labelField("name");

See Also:
Since:
10.0.0
  • Method Details

    • create

      public static SelectionDef create(String rowIdField)
      Starts a new SelectionDef bound to the specified stable row-id field.
      Parameters:
      rowIdField - The row-data key whose value is this row's stable identity (e.g. "id" or "incidentId"). Must not be null or blank.
      Returns:
      A new SelectionDef, with selectAll() defaulting to true.
      Throws:
      IllegalArgumentException - If rowIdField is null or blank.
    • selectAll

      public SelectionDef selectAll(boolean value)
      Sets whether a select-all header checkbox is rendered alongside the per-row checkboxes.

      Select-all always applies only to the rows currently on screen (the current page's draw) — it can never reach into rows on another page, which would be indistinguishable from the off-screen-retarget risk this whole opt-in exists to close.

      Parameters:
      value - The new value. Defaults to true.
      Returns:
      This object.
    • rowIdField

      public String rowIdField()
      The row-data key used as this table's stable row identity.
      Returns:
      The row-id field name.
    • selectAll

      public boolean selectAll()
      Whether a select-all header checkbox is rendered.
      Returns:
      true if select-all is enabled.
    • scope

      Sets whether selection persists across paging/sorting/searching/refresh (SelectionDef.Scope.PERSISTENT, the default) or is dropped for any row not in the current draw (SelectionDef.Scope.PAGE).
      Parameters:
      value - The new scope. A null value resets to SelectionDef.Scope.PERSISTENT.
      Returns:
      This object.
    • selectableWhen

      Sets the rules that gate which rows can be selected at all.

      A row failing any rule renders its checkbox disabled, carrying the failing rule's reason as both a tooltip and an accessible description; select-all skips such rows entirely.

      Parameters:
      value - The gating rules. An empty or null array clears this to null (no gating).
      Returns:
      This object.
    • labelField

      public SelectionDef labelField(String value)
      Sets the row-data field used as this row's human-readable label in a confirm dialog's target list.
      Parameters:
      value - The field name. May be null (falls back to the row id).
      Returns:
      This object.
    • scope

      This selection's scope.
      Returns:
      The scope. Never null.
    • selectableWhen

      This selection's gating rules.
      Returns:
      The rules, or null if none were set.
    • labelField

      public String labelField()
      This selection's label field.
      Returns:
      The field name, or null if none was set.