textarea preformatting and wrapping in h:outputText

眉间皱痕 提交于 2019-12-13 02:21:38

问题


I am saving news from textarea in database and showing them again on a JSF page.

When I print the bean data I have it as below.

This is line 1
This is line 2

In textarea when I try to edit, I see same as above. But when I try to print in <h:outputText> I see it as below.

This is line 1 This is line 2

Even when I print using Sytem.out.println(), I see output as

This is line 1 This is line 2

Any idea how can I get this new line in <h:outputText>?


I also tried this answer which suggests to use white-space: pre.

This is working, but when the length of the text is long, all long line is coming in one line instead of next line and because of that I am getting horizontal scrollbar which is not what I want.

This answer works fine for small text but as news are large in length, this is problem.


回答1:


If you want both preformatting and wrapping, use instead:

white-space: pre-wrap;

If you want to support IE6/7 as well (which doesn't support pre-wrap), use instead:

white-space: pre;
word-wrap: break-word;


来源:https://stackoverflow.com/questions/18210987/textarea-preformatting-and-wrapping-in-houtputtext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!