Package su.onno.ui
Class ActionSpec.ActionBuilder
java.lang.Object
su.onno.ui.ActionSpec.ActionBuilder
- Enclosing class:
ActionSpec
Fluent builder for one action; setters may be called in any order.
-
Method Summary
Modifier and TypeMethodDescriptionOptional CSS color hint for compact action renderers, especially row-menu status swatches.enabledWhen(Predicate<ActionRow> enabled) Enable this action only on records where the predicate holds — disabled (greyed) elsewhere (ActionScope.ROW/ActionScope.DETAILactions).Collect input from the user before thehandlerruns: clicking the button opens a modal dialog with the fields declared here (same builder as toolbar inputs — text, textarea, date, number, select;.required()gates submit).formDefaults(Function<ActionContext, ActionSpec.FormDefaults> defaults) Compute the form's opening values server-side each time the dialog opens — the dynamic counterpart of the staticInputSpec.InputBuilder.value(String)default.handler(Function<ActionContext, ActionResult> handler) Run arbitrary server logic when clicked.A kebab-case lucide icon name (e.g.Pick the icon per record (ActionScope.ROW/ActionScope.DETAILactions) — e.g.Set the fixed human-facing label.Pick the label per record (ActionScope.ROW/ActionScope.DETAILactions).An image URL or app-static path shown instead of the lucideicon(String)— e.g.Put thisActionScope.ROWaction into the row's right-click context menu under a submenu with the given label, instead of rendering it as an inline row icon button.Route the client tourlwhen clicked ({id}is filled with the record id).Restrict this action to callers holding any of the given roles (ADMINalways passes, like entity@AccessControl).scope(ActionScope scope) visibleWhen(Predicate<ActionRow> visible) Show this action only on records where the predicate holds (ActionScope.ROW/ActionScope.DETAILactions).
-
Method Details
-
label
Set the fixed human-facing label. Surfaces without a record context, including the batch menu and batch progress messages, use this value; it is also the fallback for a dynamiclabel(Function). If omitted, the fixed label defaults to the action key. -
icon
A kebab-case lucide icon name (e.g."archive","download"). -
logo
An image URL or app-static path shown instead of the lucideicon(String)— e.g. a brand logo for a "Connect with X" button (.logo("https://cdn/github.svg")). -
color
Optional CSS color hint for compact action renderers, especially row-menu status swatches. -
scope
-
handler
Run arbitrary server logic when clicked. -
form
Collect input from the user before thehandlerruns: clicking the button opens a modal dialog with the fields declared here (same builder as toolbar inputs — text, textarea, date, number, select;.required()gates submit). The submitted scalar values reach the handler asActionContext.input(String). The form may also declare repeatablerow groups(a transient tabular grid), read back viaActionContext.inputRows(String). Server actions only — a navigation action has no handler to hand the values to. -
formDefaults
public ActionSpec.ActionBuilder formDefaults(Function<ActionContext, ActionSpec.FormDefaults> defaults) Compute the form's opening values server-side each time the dialog opens — the dynamic counterpart of the staticInputSpec.InputBuilder.value(String)default. The client fetchesGET /api/actions/{kind}/{name}/{key}/form?id=…when the modal opens and seeds the scalar inputs fromActionSpec.FormDefaults.values()and the row groups fromActionSpec.FormDefaults.rows()(replacing the single blank row). The function receives anActionContextcarrying the surface kind/name, the record id (when opened from a row/detail; null for toolbar/page opens) and the caller — its inputs/rows are empty.Must be read-only — it runs on a GET and may be called any number of times. It is not invoked for batch runs (no single record to compute against); a thrown exception is logged and the dialog falls back to the static defaults. Requires a
form.a.action("startPrint").form(f -> f.group("prints", …)) .formDefaults(ctx -> FormDefaults.ofRows("prints", freePrinters(ctx.id()))) .handler(this::startPrint); -
roles
Restrict this action to callers holding any of the given roles (ADMINalways passes, like entity@AccessControl). The server rejects a caller without a matching role, and page-action buttons the caller can't run are hidden from the rendered page. Unset (the default) means any caller the surface already admits — for an entity action that's the entity's write roles; for a page action, any authenticated user. -
icon
Pick the icon per record (ActionScope.ROW/ActionScope.DETAILactions) — e.g.playvspauseby the record's state. Overrides the fixedicon(String)on records it resolves. -
label
Pick the label per record (ActionScope.ROW/ActionScope.DETAILactions). Overrides the fixedlabel(String). For a server row action exposed to batch selection, also set a fixed human-facing label because batch surfaces have no single record context. -
visibleWhen
Show this action only on records where the predicate holds (ActionScope.ROW/ActionScope.DETAILactions). -
enabledWhen
Enable this action only on records where the predicate holds — disabled (greyed) elsewhere (ActionScope.ROW/ActionScope.DETAILactions).
-