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

前端 未结 3 1402
广开言路
广开言路 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:20

    This is normal behaviour, in HTML consecutive whitespace such as spaces and linebreaks gets normalized so it displays just as a single space. You would get the same display if you included the text with linebreaks directly in the HTML source. To honor linebreaks in the the output you would have to wrap the text in pre tags or apply a stylesheet class:

    For other possible values for the white-space attribute look at this page: http://www.w3schools.com/cssref/pr_text_white-space.asp

提交回复
热议问题