print: placeholder format specifier ({{Price:#,##0.00}}, {{Date:dd.MM.yyyy}}) - #6983
Merged
Conversation
….yyyy}})
A .print template had no way to control how a bound value renders.
DataBinder money-formats only Double/Float/BigDecimal, and both print
paths parse the {document, items} JSON with LONG_OR_DOUBLE - so a money
value that lands on a whole figure (the browser strips the trailing .00:
JSON.stringify(5390.00) emits 5390) arrives as a Long and prints bare
next to a formatted totals block. Dates had the sibling problem: an ISO
2026-08-29 could not be reformatted to a local convention.
Blanket-formatting Long in the binder would be wrong (ids, years), so
the knob goes to the template author: an operand may carry a pattern
after its first colon, mirroring the {date:yyyyMMdd} token of the
declarative fileName patterns. A Number (Long included) formats via
DecimalFormat with the existing ROOT + space-grouping symbols; a
temporal - or the ISO string a feeder emits for one - via
DateTimeFormatter. The first colon splits, so time patterns keep their
own colons ({{At:HH:mm}}). A pattern the value cannot satisfy, or a
value of any other shape, falls back to the default rendering - a
printout never shows an exception, per the parser's leniency contract.
|-fallback semantics are unchanged (blankness judged on the rendered
result); no existing template carries a colon in a placeholder body, so
every shipped template renders byte-identical.
Fixes #6982
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An optional format pattern on a
.printplaceholder operand, after its first::Number(any subtype,Longincluded) formats viaDecimalFormatwith the existing ROOT + space-grouping symbolsPrintFeederemits for one — formats viaDateTimeFormatter.ofPattern|-fallback semantics unchanged (blankness judged on the rendered result, last operand always renders)Why
DataBinder.stringifymoney-formats onlyDouble/Float/BigDecimal, and both print paths (PrintEndpoint,PrintFacade) parse the payload with GsonLONG_OR_DOUBLE— so whether a money value formats is decided by whether the JSON happens to carry a decimal point. The browser path makes that systematic:JSON.stringify(5390.00)emits5390, which lands as aLongand prints bare next to a formatted totals block, and nothing the template author writes can fix it. Blanket-formattingLongin the binder would be wrong (ids, years), so the knob belongs to the template, mirroring the{date:yyyyMMdd}token the declarativefileNamepatterns already use (#6904).Backward compatible: no existing
.printtemplate (shipped or generated) carries a:inside a placeholder body, so every template renders byte-identical without the specifier.Testing
Six new
DataBinderTestcases: integral-Long money formatting + grouping, explicit pattern overriding the default money pattern, temporal and ISO-string date reformatting, first-colon split (HH:mm), fallback on an unsatisfiable pattern (string + invalid date pattern), and format combined with|alternatives. Fullmodules/parsers/documentsuite green (110 tests).Fixes #6982
🤖 Generated with Claude Code