在JSF中显示辅助bean的值时,不要折叠空格 [英] Do not collapse whitespace when displaying the value of the backing bean in the JSF

查看:114
本文介绍了在JSF中显示辅助bean的值时,不要折叠空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现JSF页面上显示的backing bean值会自动折叠空白。我怎样才能让显示的值不会折叠空格?



例如,我有一个MBean,它有一个String变量 test 并赋值

test test

,当我使用< h1> $ {MBean.test}< / h1> 来呈现它时,它只是给出 test test 中间的所有空格都只会缩小到一个空格。



如果我从MBean中显示ArrayList,使用< rich:dataTable> 的表格格式,所有的空格也会被折叠。

更新:我仍然认为它特定于JSF,因为当我使用
< h:inputText value =#{MBean.test}/> ,渲染的输入文本框会折叠所有的白色空间。在这种情况下,我怎样才能保留所有的空白空间?

解决方案

这不是JSF特有的。这是针对HTML的



您可以通过将其修改为HTML < pre> 元素:

 < h1>< pre>#{bean.text}< / pre> < / H1> 

或者通过应用CSS white-space:pre 关于HTML元素:

  h1 {
white-space:pre;





(如你所见,它也出现在你的问题上还有Stackoverflow,因为它也不会通过 white-space保留空白:pre

I found that the backing bean value displayed on the JSF page will collapse the white-space automatically .How can I make the value displayed do not collapse the white-space??

For example , I have a MBean which has a String variable test and assign the value

"test                  test"

, when I render it using <h1>${MBean.test}</h1> , it just give out test test which all the white-spaces in the middle collapse to a white-space only.

This behavior also happens if I display the ArrayList from the MBean in the table format using the <rich:dataTable> , all the white-spaces will be collapsed too.

Updated: I still think that it is specific to the JSF , because when I use <h:inputText value="#{MBean.test}"/> , the rendered input text box will collapse all the white-spaces.How can I preserve all the white-spaces in this case??

解决方案

This is not specific to JSF. This is specific to HTML

You can fix it by either putting it in a HTML <pre> element:

<h1><pre>#{bean.text}</pre></h1>

Or by applying CSS white-space: pre on the HTML element:

h1 { 
    white-space: pre;
}

(as you see, it also occurs on your question here on Stackoverflow as well, since it also doesn't preserve whitespace by white-space: pre)

这篇关于在JSF中显示辅助bean的值时,不要折叠空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆