Class TableSpec

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

public final class TableSpec extends Object
Java description of one datatables view: data source, columns, ribbon, row styling, row actions, row detail, selection and bulk actions. It replaces hand-written <@card type="datatables"> JSON5 for apps that build pages in Java, and toCardBody() serializes to exactly the card body the FTL path produces. All behavior (paging, search, rendering, actions) stays in juneau-views.js; this type never calls a card-type handler directly — see the class's rendering note on toCardBody().

Column.defaultVisible(false) only hides a column when the client's columnConfig (juneau-config.js) is on.

Example:

TableSpec t = TableSpec.create("slo") .rowType(SloPod.class) .dataUrl("/rest/slo/data") .defaultOrder("pod", TableSpec.Sort.ASC) .columns( Column.create("pod").label("Pod").className("ssc-id-cell"), Column.create("incidentKey").label("Incident").render("linked").href("{incidentUrl}"), Column.create("rootCause").label("Root cause").defaultVisible(false)) .ribbon(RibbonItem.refresh(), RibbonItem.export("copy", "csv")) .rowClass("analysisState", Op.EQ, "degraded", "row-degraded") .rowActions(RowAction.create("analyze").label("Analyze pod") .endpoint("/rest/slo/analyze").method(RowAction.Method.POST)) .detail(RowDetail.create("/rest/slo/data/{id}").title("{pod}") .region(RegionDef.create("slo-detail").populate("slo-detail"))); t.validate(); Map<String,Object> body = t.toCardBody(); // the unwrapped catalog

Since:
10.0.0
  • Method Details

    • create

      public static TableSpec create(String id)
      Starts a new table definition.
      Parameters:
      id - The table's card id. Must not be null or blank, and must match ^[A-Za-z][A-Za-z0-9_-]{0,63}$.
      Returns:
      A new TableSpec, with no columns or dataUrl yet set.
      Throws:
      IllegalArgumentException - If id is null, blank, or malformed.
    • rowType

      public TableSpec rowType(Class<?> type)
      Sets the row type by its simple name, as TableCatalog did — documentation metadata only; it has no effect on rendering or validation.
      Parameters:
      type - The row type. Can be null to unset.
      Returns:
      This object.
    • rowType

      public TableSpec rowType(String name)
      Sets the row type by name directly.
      Parameters:
      name - The row type name. Can be null to unset.
      Returns:
      This object.
    • dataUrl

      public TableSpec dataUrl(String url)
      Sets the table's data source URL.
      Parameters:
      url - The URL. Required by validate().
      Returns:
      This object.
    • dataMode

      Sets whether paging/sorting/search run client-side or against dataUrl on every draw.
      Parameters:
      mode - The mode. Defaults to TableSpec.DataMode.CLIENT when never called (omitted from the wire, since juneau-views.js already defaults to client mode).
      Returns:
      This object.
    • defaultOrder

      Appends one default sort column. Repeatable — later calls add secondary sort keys.
      Parameters:
      column - The column name. Must not be null or blank.
      dir - The sort direction. Must not be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If column is null/blank, or dir is null.
    • columns

      public TableSpec columns(Column... cols)
      Appends columns, in display order.
      Parameters:
      cols - The columns. Must not be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If cols names a Column.name() already appended by an earlier call.
    • operators

      Sets the table-level default SearchOperatorSet, inherited by any searchable column that declares none of its own.
      Parameters:
      table - The operator set. Can be null to clear it back to absent.
      Returns:
      This object.
    • ribbon

      public TableSpec ribbon(RibbonItem... items)
      Appends ribbon (toolbar) items, in display order.
      Parameters:
      items - The items. Must not be null.
      Returns:
      This object.
    • rowClass

      public TableSpec rowClass(String field, Op op, Object value, String cssClass)
      Appends a value-based row-class rule (juneau-views.js's evaluateRowClassRules): a row whose field is eq/ne the given value gets cssClass added to its <tr>.
      Parameters:
      field - The row-data field to test. Must not be null or blank.
      op - The operator. Must be Op.EQ or Op.NE.
      value - The comparison value. Must not be null.
      cssClass - The CSS class to add on a match (serialized as the wire key class). Must not be null or blank.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If any argument is missing, or op does not take a value.
    • rowClass

      public TableSpec rowClass(String field, Op op, String cssClass)
      Appends a presence-based row-class rule: a row whose field is present/ absent gets cssClass added to its <tr>.
      Parameters:
      field - The row-data field to test. Must not be null or blank.
      op - The operator. Must be Op.PRESENT or Op.ABSENT.
      cssClass - The CSS class to add on a match (serialized as the wire key class). Must not be null or blank.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If any argument is missing, or op requires a value.
    • rowActions

      public TableSpec rowActions(RowAction... actions)
      Appends row actions, in menu order.
      Parameters:
      actions - The actions. Must not be null.
      Returns:
      This object.
    • rowActions

      public TableSpec rowActions(List<RowAction> actions)
      Appends row actions from a list, in menu order.
      Parameters:
      actions - The actions. Must not be null.
      Returns:
      This object.
    • detail

      public TableSpec detail(RowDetail value)
      Sets the per-row detail panel.
      Parameters:
      value - The detail config. Can be null to clear it.
      Returns:
      This object.
    • selection

      Sets the row-selection opt-in.
      Parameters:
      value - The selection config. Can be null to clear it.
      Returns:
      This object.
    • bulk

      public TableSpec bulk(BulkMutateDef value)
      Sets the bulk-mutate opt-in. Requires selection(SelectionDef) to also be set.
      Parameters:
      value - The bulk config. Can be null to clear it.
      Returns:
      This object.
    • pollIntervalMs

      public TableSpec pollIntervalMs(long ms)
      Sets the auto-refresh poll interval.
      Parameters:
      ms - The interval in milliseconds. Must be positive.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If ms is not positive.
    • quickStats

      public TableSpec quickStats(String id, QuickStat... items)
      Sets the table's quick-stats strip.
      Parameters:
      id - The strip's own id, serialized as quickStats.id. Must not be null or blank.
      items - The tiles, in display order. Must not be empty.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If id is null/blank, or items is empty.
    • urlState

      public TableSpec urlState(String... names)
      Declares URL-state directives this table's address bar carries, so their values reach the table's server requests.

      Each name selects one of the built-in directives (day, ids or window); any other name is refused, because this method does not register codecs and the page contract only carries the built-ins. A name not yet declared is emitted as an empty configuration object, which means the directive's defaults; a name already declared keeps its configuration (for example a day param set by urlStateDayParam(String)). This method never clears configuration. Directives are emitted in the order they were first declared. The call is atomic: every name is validated before any is declared, so if one is refused nothing is changed.

      Parameters:
      names - The directive names; each one of day, ids or window.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If a name is null, blank or not a built-in directive.
    • urlStateDayParam

      Declares the day URL-state directive and names the request query parameter it sends the selected day under.

      urlState("day") sends the day as a day parameter; this form is for a server whose parameter has another name. The directive is emitted as urlState.day.param, in the position day was first declared. Calling this again replaces the parameter name (the last call wins).

      Parameters:
      param - The query-parameter name; must match ^[A-Za-z][A-Za-z0-9_-]{0,63}$.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If param is null, blank, or malformed.
    • urlState

      public TableSpec urlState(String name, Map<String,Object> config)
      Declares a URL-state directive together with its options.

      This is the configurable form of urlState(String...) for the three built-in directives; every option the client's built-in codecs accept can be expressed, so a page needs no hand-written map to configure one:

      • ids — param (request parameter name, default ids) and max (an integer >= 1, default 200).
      • window — params, a map that may hold start and/or end (the request parameter names, defaults start/end).
      • day — param (request parameter name, default day); same as urlStateDayParam(String).
      Any other directive name is refused: this method does not register codecs, and the page contract only carries the built-ins.

      Restrictions (deliberate, so the wire contract and the builder agree): every parameter name must match ^[A-Za-z][A-Za-z0-9_-]{0,63}$ (the same grammar as day.param), and max must be an integer (Integer, Long, Short or Byte) of at least 1. The client's own fallbacks for a falsy, string or fractional max, or for an unusual parameter name, are refused here rather than reproduced. The result is the same value an FTL page writes as urlState: {ids:{param:'pid',max:50}}.

      Merge, not replace. The options are merged into any entry already declared for name: each option given here overwrites the same option declared earlier (the last call wins, as with urlStateDayParam(String)), options not named here are kept, and window.params is merged key by key. Like urlState(String...) this never clears configuration, and an empty map just declares the directive. The directive keeps the position it was first declared in. The call is atomic: if any option is refused, nothing is changed.

      Parameters:
      name - The directive name; one of day, ids or window.
      config - The directive options; deep-copied, so later changes to the map have no effect. Must not be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If the name is null, blank or not a built-in directive, the config is null, or an option is unknown for a built-in directive, mistyped, or out of range (a parameter name that is malformed, a max that is not a positive integer, a window.params key other than start/end).
    • primary

      public TableSpec primary(boolean v)
      Sets whether this table is the page's primary table (affects layout only).
      Parameters:
      v - The new value.
      Returns:
      This object.
    • columnConfig

      public TableSpec columnConfig(boolean v)
      Sets whether this table offers the View Settings dialog (column chooser, search and sort settings).
      Parameters:
      v - The new value.
      Returns:
      This object.
    • columnConfig

      public TableSpec columnConfig(Map<String,Object> options)
      Sets the View Settings dialog options, serialized as the columnConfig object (for example {"chooser": true}).
      Parameters:
      options - The options, copied at call time. Must not be null.
      Returns:
      This object.
    • copyLink

      public TableSpec copyLink(boolean v)
      Sets whether the table offers a copy-link control for its current view state.
      Parameters:
      v - The new value.
      Returns:
      This object.
    • cleanAddress

      public TableSpec cleanAddress(boolean v)
      Sets whether the browser address bar is cleaned of the table's view-state parameters.
      Parameters:
      v - The new value.
      Returns:
      This object.
    • pausePollingWhileEditing

      public TableSpec pausePollingWhileEditing(boolean v)
      Sets whether polling pauses while an editing surface (an open detail row or action dialog) is bound to this table.
      Parameters:
      v - The new value.
      Returns:
      This object.
    • cssClass

      public TableSpec cssClass(String value)
      Sets the CSS class applied to this table's card. It is carried on the card placement, not in the card body returned by toCardBody().
      Parameters:
      value - The class list. Can be null to unset.
      Returns:
      This object.
    • id

      public String id()
      Returns:
      This table's id.
    • columns

      public List<Column> columns()
      Returns:
      The columns, in display order.
    • rowActions

      Returns:
      The row actions, in menu order.
    • cssClass

      public String cssClass()
      Returns:
      The card CSS class, or null.
    • detail

      Returns:
      The per-row detail panel, if set.
    • validate

      public void validate()
      Validates this table. A duplicate column and a rowClass op/value mismatch are checked eagerly by columns(Column...) and rowClass, and an unknown export button by RibbonItem.export(String...), so none of those can be seen here.
      Throws:
      IllegalStateException - If any check fails.
    • toCardBody

      public JsonMap toCardBody()
      Builds this table's catalog-form card body, with no contractVersion anywhere (the client stamps every contract version). This is the only place in this type that knows the datatables wire shape. The result is the unwrapped catalog the datatables card type reads, and is rendered the same single way <@card> is, by the page mixin's cardTypes.toCard(CardSource.create("datatables", id()) .bodyMap(toCardBody()).build()); this type never calls a card-type handler directly.

      The body holds only plain data (maps, lists, strings, numbers, booleans), the same shape a parsed body has.

      Each column carries its effective operator set (its own, else operators(SearchOperatorSet)).

      Returns:
      The catalog, with keys in a fixed order and absent optional values omitted.