简体   繁体   中英

textarea preformatting and wrapping in h:outputText

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM