Do not collapse whitespace when displaying the value of the backing bean in the JSF

浪尽此生 提交于 2019-12-13 07:46:24

问题


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??


回答1:


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)




回答2:


Sun's JavaServer Faces implementation (1.2_07-b03-FCS) has the same issue on Webshpere Application Server 7.0.0.21 for the CSS white-space: pre



来源:https://stackoverflow.com/questions/4676166/do-not-collapse-whitespace-when-displaying-the-value-of-the-backing-bean-in-the

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