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

PropertyReturnsDescription
attributesMap<String,Object>Arbitrary name/value attributes attached to this narrative, used for example to pass structured detail alongside the message text.
htmlStringRenders this narrative's items as an HTML unordered list, with translation applied.
itemsList<NarrativeItem>The items appended to this narrative so far, in the order they were added.
textStringRenders 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.

ParameterDescription
textthe message text, using "{}" as a placeholder for each argument
argsthe 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.

ParameterDescription
namethe attribute name
valthe 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.

ParameterDescription
dedupetrue 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.

ParameterDescription
messagesthe messages to append, ignored if null
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.