Preserve Linebreaks in ItemDetails

Hi,

have some text containing linebreaks and newlines that i want to show inside an itemDetail on a grid. My problem is that the linebreaks and newlines are not preserved and instead one long line of text is showing.

I tried LitRenderer and TextRenderer. Did i miss some configuration to do this?

I already tried replacing the linebreaks with html markup, e.g. message.replace("\n", "<br>")). This also does not work, cause then the html is literally in the text.

What can i do?

Hello, you have to wrap this “string with html code” by Html component. Html component takes string as parameter. But this code must be one html element (see documentation).

new Html("<span>text with <br> new line</span>");

You could also display a TextArea, this will show newlines (\n) the way you want.
You can do this with a ComponentRenderer.

setItemDetailsRenderer(new ComponentRenderer<>(item -> {
    TextArea textArea = new TextArea();
    textArea.setValue(item.getDesciption());
    textArea.setReadOnly(true);
    return textArea;
}));