Class PageSpec
A PageSpec renders nothing itself. Its values are seeded into the request's PageCapture before any
directive runs, so a built page goes through the same <@console> chrome and emits the same
#juneau-page contract and the same toolkit asset tags as an FTL page. Chrome (brand, nav tree, footer, theme tokens) stays in the app's
chrome template.
Example:
Example:
- Since:
- 10.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionAdds a passthrough attribute, applied to the view this spec builds.Adds a header badge.Sets one<body>attribute.bridge(BridgeDecl decl) Declares a server bridge; repeatable.Looks up a declared card by id.Adds a custom-type card with no inline markup.Adds a custom-type card that also takes inline markup.cards()static PageSpeccreate()Creates a new, empty spec.Sets the CSRF body attributes:data-juneau-csrfand, ifheaderNameis non-blank,data-juneau-csrf-header.Adds page CSS URLs, appending any not already present.dashboard(DashboardSpec dashboard) Adds the page's dashboard: a rail of filter sections beside a grid of card panels.data(DataSourceDef def) Declares a data source, published ondata:<id>; repeatable.Declares a derived data source, published ondata:<as>; repeatable.Seeds page-level facts, whichvisibleWhenrules test on the client.Adds a passthrough HTTP response header, applied to the view this spec builds.Sets the header'ssubtitleand/oruserMenu.Adds anhtmlcard whose body ismarkup, with no title.Adds anhtmlcard whose body ismarkup, with a title.Adds anhtmlcard whose body ismarkup, lettingcardadjust the card (title, CSS class, and so on).Adds anhtmlcard whose body is fetched fromsrc, with a title, unsanitized.Adds anhtmlcard whose body is fetched fromsrc, with a title, optionally rebuilt through the views attribute-allowlist sanitizer.Adds page init-script URLs, appending any not already present.navUnder(String parentIdPath, PageCapture.NavAdder adder) Queues a child to add under an existing chrome nav node, resolved once the chrome's own nav tree exists.Pins the page's colour scheme.schemeToggle(boolean value) Lets the visitor override the page's colour scheme with a stored choice.tab()Sets the<@page tab>-equivalent active-nav path.Adds adatatablescard fortable, with no title.Adds adatatablescard fortable, with a title.Adds adatatablescard fortable, lettingcardadjust the card.template()Sets the page template, overriding the mixin's configured chrome template.Selects a stock theme by name.Sets the page title.Adds toolkit names, appending any not already present.toolkits()Declares a page-level custom topic; repeatable.view(RestRequest req) Builds the view for this spec.
-
Field Details
-
ATTR
Data-model attribute that carries the spec into the render.- See Also:
-
-
Method Details
-
create
Creates a new, empty spec.- Returns:
- A new spec.
-
template
Sets the page template, overriding the mixin's configured chrome template.- Parameters:
pageTemplateName- The template name (no.ftlh).- Returns:
- This object.
-
attr
Adds a passthrough attribute, applied to the view this spec builds.- Parameters:
key- The attribute name.value- The attribute value.- Returns:
- This object.
-
header
Adds a passthrough HTTP response header, applied to the view this spec builds.- Parameters:
name- The header name.value- The header value.- Returns:
- This object.
-
title
Sets the page title. The spec always wins over<@console title>.- Parameters:
v- The title.- Returns:
- This object.
-
tab
Sets the<@page tab>-equivalent active-nav path.- Parameters:
idPath- A'/'-separated id path, e.g."home/skills/core".- Returns:
- This object.
- Throws:
IllegalArgumentException- If blank, or any segment is blank.
-
theme
Selects a stock theme by name. Validated immediately viaConsoleChromeMixin.stockTheme(String).- Parameters:
stockName- One ofConsoleChromeMixin.BUILTIN_THEME_NAMES.- Returns:
- This object.
- Throws:
IllegalArgumentException- IfstockNameis not a built-in stock-theme name.
-
scheme
Pins the page's colour scheme.auto(the default) follows the browser'sprefers-color-scheme;lightanddarkpin the page. An explicit<@console scheme="…">on the page template wins over this value.- Parameters:
name- One ofConsoleChromeMixin.SCHEMES.- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifnameis not a known scheme.
-
schemeToggle
Lets the visitor override the page's colour scheme with a stored choice.An explicit
<@console schemeToggle="…">on the page template wins over this value.- Parameters:
value- Whether the stored choice is honoured.- Returns:
- This object.
-
toolkit
Adds toolkit names, appending any not already present.- Parameters:
names- The toolkit names.- Returns:
- This object.
-
css
Adds page CSS URLs, appending any not already present.- Parameters:
urls- The CSS URLs.- Returns:
- This object.
-
init
Adds page init-script URLs, appending any not already present.- Parameters:
urls- The script URLs.- Returns:
- This object.
-
header
Sets the header'ssubtitleand/oruserMenu. These are the only two header fields this builder may set; every other field belongs in the chrome template.- Parameters:
c- Mutates a scratchPageCapture.HeaderSpec.- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifcsets any field other thansubtitle/userMenu, or the user menu has a key the page contract does not allow.
-
table
Adds adatatablescard fortable, with no title.- Parameters:
table- The table. Validated and snapshotted immediately; later changes to it do not affect this page.- Returns:
- This object.
-
table
Adds adatatablescard fortable, with a title.- Parameters:
table- The table.title- The card title.- Returns:
- This object.
-
table
Adds adatatablescard fortable, lettingcardadjust the card.The table's CSS class, if set, is carried onto the card wrapper before
cardruns, socardmay override it. The card body is produced by the card-type registry when the spec is seeded into a page.- Parameters:
table- The table.card- Mutates the card. May benull .- Returns:
- This object.
-
html
Adds anhtmlcard whose body ismarkup, with no title.- Parameters:
id- The card id.markup- The markup, emitted as<template data-card=id>. Must not benull .- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifmarkupisnull .
-
html
Adds anhtmlcard whose body ismarkup, with a title.- Parameters:
id- The card id.title- The card title.markup- The markup. Must not benull .- Returns:
- This object.
-
html
Adds anhtmlcard whose body ismarkup, lettingcardadjust the card (title, CSS class, and so on).cardmust not also setsrcortemplate.- Parameters:
id- The card id.markup- The markup. Must not benull .card- Mutates the card. May benull .- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifmarkupisnull , orcardsetssrcortemplate.
-
htmlSrc
Adds anhtmlcard whose body is fetched fromsrc, with a title, unsanitized. SeehtmlSrc(String,String,String,boolean)for the trust boundary.- Parameters:
id- The card id.title- The card title. May benull for no title.src- The same-origin path of the HTML fragment endpoint. Must not be blank.- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifsrcisnull or blank.
-
htmlSrc
Adds anhtmlcard whose body is fetched fromsrc, with a title, optionally rebuilt through the views attribute-allowlist sanitizer. The equivalent of<@card type="html" src="..." sanitize=true>.Trust boundary:
With
sanitizefalse the shell fetchessrcand inserts the returned HTML as-is through a raw HTML-sink assignment, unsanitized, the same trust level asfooter.text(seeHtmlCardType). The endpoint must therefore be a trusted first-party route, must never be derived from request data, and must escape any data it embeds in the fragment.srcmust be a same-origin path; an absolute URL, a scheme,//,..or a backslash is refused when the page is built, exactly as for every other card.With
sanitizetrue the fragment is rebuilt through the views attribute-allowlist sanitizer instead: script,on*handlers,javascript:anddata:URLs and every attribute off the allowlist are dropped, and benign markup (text, tables, links, images) survives. It needs the views toolkit on the page; without the toolkit nothing is painted (the shell fails closed rather than inserting the fragment unsanitized). The sanitizer does not remove the need to escape any data you embed in the fragment. Turn it on when the fragment's content is not fully under your control (it embeds user-supplied or third-party markup, or comes from an endpoint you do not own); leave it off for a fragment that needsclass,id,style, forms, SVG or iframes, which the allowlist drops. The default stays off.- Parameters:
id- The card id.title- The card title. May benull for no title.src- The same-origin path of the HTML fragment endpoint. Must not be blank.sanitize- Whether to rebuild the fetched fragment through the sanitizer.- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifsrcisnull or blank.
-
card
Adds a custom-type card with no inline markup.When the page renders, a card of an adopter type (any type that is not reserved) is built as
<@card>builds it: its body map is the authored body, the type's registeredCardTypeHandlervalidates it and returns the fragment the card carries, and an invalid body fails the render with the<@card>message. An unregistered type takes the generic passthrough, so its body map is carried as-is.- Parameters:
card- The card. Its type must not be a removed type or one with a dedicated method.- Returns:
- This object.
-
card
Adds a custom-type card that also takes inline markup.- Parameters:
card- The card. Seecard(CardSpec).markupOrNull- The markup, ornull . For an adopter type it is the card's body, as the content of<@card>is: the handler parses it (JSON5) or captures it as<template data-card=card.id()>, andsubscribes/publisheskeys in JSON5 markup are wired onto the card. A card takes at most one of a body map, non-blank markup,templateorsrc.- Returns:
- This object.
-
dashboard
Adds the page's dashboard: a rail of filter sections beside a grid of card panels.The panel and card-section cards built by the dashboard are added to this page as ordinary cards, and the
dashboardtoolkit pack is added (just beforechartswhen that is listed). A by-id panel (panel("notes")) must name a card added before this call, for example withhtml(String, String).- Parameters:
dashboard- The dashboard.- Returns:
- This object.
- Throws:
IllegalArgumentException- E-77 on any dashboard problem, or if the page already has a dashboard.
-
csrf
Sets the CSRF body attributes:data-juneau-csrfand, ifheaderNameis non-blank,data-juneau-csrf-header.- Parameters:
token- The CSRF token value.headerName- The CSRF header name, ornull /blank to omit the header attribute.- Returns:
- This object.
-
bodyAttr
Sets one<body>attribute.- Parameters:
name- The attribute name.value- The attribute value;& < > "are escaped.- Returns:
- This object.
-
cards
- Returns:
- The declared cards, in declaration order; a snapshot.
-
card
Looks up a declared card by id.- Parameters:
id- The card id.- Returns:
- The card, or empty if none was declared with this id.
-
badge
Adds a header badge. The Java twin of<@badge>.- Parameters:
def- The badge. Must not benull .- Returns:
- This object.
- Throws:
IllegalArgumentException- IfBadgeDef.validate()rejects it.
-
facts
Seeds page-level facts, whichvisibleWhenrules test on the client. Repeated calls merge, last wins, on this side only; the strict check against chrome-supplied facts runs once, at</@console>.- Parameters:
v- The facts. Leaves must be strings, numbers, booleans, string lists or maps.- Returns:
- This object.
- Throws:
IllegalArgumentException- On a leaf of any other type.
-
topic
Declares a page-level custom topic; repeatable. Unions with FTL<@topic>.- Parameters:
decl- The declaration; needsretainandpublisher.- Returns:
- This object.
- Throws:
IllegalArgumentException- E-46 if the topic is already declared with a differentretainorpublisher.
-
bridge
Declares a server bridge; repeatable. Unions with FTL<@bridge>.- Parameters:
decl- The bridge.- Returns:
- This object.
- Throws:
IllegalArgumentException- E-51 on a duplicate id, or fromBridgeDecl.toMap().
-
data
Declares a data source, published ondata:<id>; repeatable.- Parameters:
def- The source.- Returns:
- This object.
- Throws:
IllegalArgumentException- E-76 on a duplicate id or a bad declaration; also on a null definition.
-
data
Declares a derived data source, published ondata:<as>; repeatable.- Parameters:
def- The derived source.- Returns:
- This object.
- Throws:
IllegalArgumentException- E-76 on a duplicate id or a bad declaration; also on a null definition.IllegalStateException- IfDerived.as(String)was not called.
-
template
- Returns:
- The template name, or
null if unset (the mixin's chrome template applies).
-
tab
- Returns:
- The tab path, or
""if unset.
-
toolkits
- Returns:
- The toolkit names, in declaration order.
-
view
Builds the view for this spec.The template is
template(String)when set, else theConsoleFreemarkerMixin's chrome template. A built spec is not modified by rendering, so it may be cached and reused across requests. Callspec.view(req)on each request: a reusedFreemarkerViewwould share one adoption flag.- Parameters:
req- The current REST request.- Returns:
- A view for the template, carrying this spec and every
attr(String, Object)/header(String, String)passthrough. - Throws:
IllegalStateException- If no template was set and the request has noConsoleFreemarkerMixinbean.IllegalArgumentException- If this spec has no page template and its bus wiring fails R-10 / R-11.
-