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开发者_C百科 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
)
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
精彩评论