An ordered collection of narrative items (short translated messages) built up while processing a request, such as validation failures or status notes, and rendered later as plain text or an HTML list. Items are appended with append() or attr(), and read back with getText(), toList() or getHtml(). When translation is enabled (the default) each item's text is passed through the translation service when it is rendered.
Properties
| Property | Returns | Description |
|---|---|---|
| attributes | Map<String,Object> | Arbitrary name/value attributes attached to this narrative, used for example to pass structured detail alongside the message text. |
| html | String | Renders this narrative's items as an HTML unordered list, with translation applied. |
| items | List<NarrativeItem> | The items appended to this narrative so far, in the order they were added. |
| text | String | Renders this narrative's items as plain text, one per line, with translation applied. |
Methods
getItems() · append(String text, Object args) · append() · getAttributes() · attr(String name, Object val) · getHtml() · html(boolean dedupe) · getText() · toList() · appendAll(List<String> messages)
getItems()
Returns: List<NarrativeItem>
The items appended to this narrative so far, in the order they were added.
append(String text, Object args)
Returns: Narrative
Appends a new item to this narrative with the given text and format arguments. The text may use "{}" as a placeholder for each argument.
| Parameter | Description |
|---|---|
text | the message text, using "{}" as a placeholder for each argument |
args | the values to substitute into the placeholders, in order |
append()
Returns: NarrativeItem
Appends a new, empty item to this narrative and returns it so its properties can be set directly.
getAttributes()
Returns: Map<String,Object>
Arbitrary name/value attributes attached to this narrative, used for example to pass structured detail alongside the message text.
attr(String name, Object val)
Returns: Narrative
Sets an attribute on this narrative.
| Parameter | Description |
|---|---|
name | the attribute name |
val | the attribute value |
getHtml()
Returns: String
Renders this narrative's items as an HTML unordered list, with translation applied.
html(boolean dedupe)
Returns: String
Renders this narrative's items as an HTML unordered list, with translation applied, optionally removing duplicate item text.
| Parameter | Description |
|---|---|
dedupe | true to omit items whose rendered text duplicates an item already rendered |
getText()
Returns: String
Renders this narrative's items as plain text, one per line, with translation applied.
toList()
Returns: List<String>
Renders this narrative's items to a list of strings, after having translations applied.
appendAll(List<String> messages)
Returns: void
Appends each of the given messages to this narrative as a plain, untranslated item.
| Parameter | Description |
|---|---|
messages | the messages to append, ignored if null |