Vaadin 23 preformatted text output

Viewed 49

In Vaadin 8 there is the possibility to show preformatted text with help of the Label component -

Label preLabel = new Label(
    "Preformatted text is shown in an HTML <pre> tag.\n" +
    "Formatting such as\n" +
    "  * newlines\n" +
    "  * whitespace\n" +
    "and such are preserved. HTML tags, \n"+
    "such as <b>bold</b>, are quoted.",
    ContentMode.PREFORMATTED);

https://vaadin.com/docs/v8/framework/components/components-label

How to achieve the same with Vaadin 23 ? I need to pretty print text on the page which contains line breaks \n

1 Answers

The Html class in Flow is intended for freeform HTML content: https://vaadin.com/api/platform/23.1.4/com/vaadin/flow/component/Html.html

Note that the content given to it must be enclosed in a top-level html element, e.g. "<span>Preformatted<b>stuff</b></span>" is ok, while "Preformatted <b>stuff</b>" is not.

If you only need line breaks, however, you could also try the Pre class which renders as a element https://vaadin.com/api/platform/23.1.4/com/vaadin/flow/component/html/Pre.html

E.g. Pre pre = new Pre("This text has line\nbreaks");

Related