h:outputText does not break \r\n characters into new lines

前端 未结 3 1389
广开言路
广开言路 2020-11-29 23:45

I have a String variable which contains carriage returns and new lines \\r\\n.

text = \"Text1\\r\\nText2\\r\\nText3\";
3条回答
  •  有刺的猬
    2020-11-30 00:13

    The previous answers caused problems for me for large amounts of text, like extremely wide output (no text wrap), which style="white-space: pre-wrap" did not fix; or it just displayed the <br/> as text, not as a line ending.

    In the end I used the h:inputTextarea component to display the text and made it 'read only' which worked straight off without replacing the line breaks, nor having to use the extra styles or styleClasses. And, it is resizeable to suit the user's needs, which is a bonus.

     
    

    For small amounts of text, I found the pre-wrap option, as suggested by henko above, to work well.

提交回复
热议问题