本文介绍了textarea预先格式化和包装在h:outputText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在数据库中保存textarea中的新闻,并在JSF页面上再次显示。

当我打印bean数据时, >

在textarea当我尝试编辑,我看到同样如上。但是当我尝试在< h:outputText> 中打印时,我看到如下。

即使在使用 Sytem.out打印时。 println(),我看到输出为

任何想法如何在< h:outputText> p>




我也尝试过,建议使用 white-space:pre



这是工作,但是当文本的长度很长时,所有的长行来一行,而不是下一行,因为我得到水平滚动条,这不是我想要的。



这个答案对小文本很好,但由于新闻长度很大,这是一个问题。

解决方案

如果您想要预先格式化包装,请改用:

 预包装

如果您还希望支持IE6 / 7(不支持 pre-wrap ),改为使用:

  
word-wrap:break-word;


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.

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.

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

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;

这篇关于textarea预先格式化和包装在h:outputText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:17