Skip to main content

Renderers and Cell Popovers

A Render (in org.apache.juneau.console.views) names how a column's value is painted into its cell. It has an id that selects a renderer, an optional meta map of string parameters, and an optional popover.

Built-in renderers​

The ids in SinkRenderAllowlist.BUILTIN_IDS are the renderers the runtime ships:

date, datetime, ts-zulu, bool, linked, truncate, json, decimal, tag, progress, pill, code.

  • linked builds an href from a template whose {property} tokens are filled from the row. Each substituted value is escaped, and the resulting URL is scheme-checked by the sink allowlist (see Security Model).
  • pill and tag render status chips using the same pill styling as <@tag> in the chrome. A pill never emits role="button".
  • edit:<actionId> shows the value with a pencil that turns the cell into an input (text, number or select, via the input and options meta). Enter or leaving the field saves through the named row action, sending the edited column as fields; Escape or an unchanged value cancels without a request. A failed save keeps the input open with the error beside it. The pencil follows the action's visibleWhen and enabledWhen. It is a cell renderer only and is not on the sink allowlist.
  • Dates render through Intl.DateTimeFormat in the browser, so they follow the user's locale.

Pill tones​

A pill column can colour each value. tone(value, StatusTone) maps one value to a status tone; categorical() gives every distinct value a stable colour from a 10-colour palette; category(value, slot) pins a value to a slot (1 to 10) so a closed value set gets distinct colours instead of a hash collision.

Render.pill()
.tone("AVAILABLE", StatusTone.SUCCESS)
.tone("PENDING", StatusTone.WARNING)
.tone("SOLD", StatusTone.NEUTRAL);

Render.pill()
.categorical()
.category("DOG", 1)
.category("CAT", 2);

On the wire:

{"id":"pill","meta":{"tones":{"AVAILABLE":"success","PENDING":"warning","SOLD":"neutral"}}}
{"id":"pill","meta":{"categorical":true,"categories":{"DOG":1,"CAT":2}}}

Matching is exact and case-sensitive. First hit wins:

  1. An entry added with tone(...).
  2. A slot pinned with category(...).
  3. categorical(): the value's hashed slot (PillPalette.slot(String)).
  4. The column-wide tone from Render.pill(StatusTone).
  5. Otherwise no colour class; in a column that uses tone(...) or category(...) an unmapped value renders as a neutral chip.

The slot colours are the theme tokens --jc-pill-cat-1-* through --jc-pill-cat-10-*.

Custom renderers​

Register a renderer before the view mounts. The definition is either a bare function (treated as the display facet) or an object with display, sort, filter, type and class facets:

JuneauViews.registerRenderer("stars", {
display: function (cellData, rowData, meta) {
const n = Number(cellData) || 0;
return "★".repeat(n); // display returns a markup string: escape anything that came from data
},
sort: function (cellData) { return Number(cellData) || 0; }
});

JuneauViews.registerRenderer(id, def) and JuneauViews.resolveRenderer(id) are defined in juneau-renders.js, which loads first in the views pack. A column that names an unknown renderer id logs a warning and falls back to the raw value. Because the display facet returns markup, a custom renderer must escape every value that came from row data; the built-ins all do.

Custom renderers apply to table cells. Field-grid fill sinks (the detail and region fields named by a RegionDef.Field.render) accept only the frozen built-in ids, and SinkRenderAllowlist.assertAllowed rejects anything else; see Security Model.

Cell popovers​

A CellPopover turns a cell into a trigger for a small popover. Set it on a Render through its popover field.

TypeFieldMeaning
CellPopovertitleThe popover heading.
CellPopoverfieldsThe PopoverField list to show.
PopoverFielddataThe row property to show.
PopoverFieldtitleThe label for that line.
PopoverFieldrenderA Render for the value, restricted to SinkRenderAllowlist.POPOVER_TEXT_IDS (date, bool, decimal, datetime, ts-zulu).

Popover fields are deliberately limited to text-only renderers: a popover cannot host a link, a code block or other interactive markup.

Render r = Render.of("truncate")
.popover(CellPopover.of(PopoverField.of("createdAt").title("Created").render("date")).title("Details"));