问题
In my sample JSF application am using rich:dataTable in page to display data.
I have 2 header to display value in rich:dataTable like following
--------------------------------
| UserDetails | EmpoyeeDetails |
--------------------------------
In message resource bundle file having key and value like
usrDet = UserDetails empDet = EmpoyeeDetails
I need to display like User in one line and Details in next line of that particular header
----------------------
| User | Empoyee |
| Details | Details |
---------------------
How to add new line character in message bundle between words? I tried by adding Hexadecimal code, Numerical Code for \n like , \u000A but its not working for me! Any Idea?
回答1:
JSF generates HTML. Newlines in HTML are not represented by the \n character, but by the <br> element.
In order to have the HTML client to interpret \n too, you need to throw in CSS white-space: pre or pre-wrap:
key = Lorem ipsum.\nDolor sit amet.
<h:outputText value="#{bundle.key}" style="white-space: pre-wrap" />
Alternatively, use <br> instead and have JSF unescape it. E.g.
key = Lorem ipsum.<br/>Dolor sit amet.
<h:outputText value="#{bundle.key}" escape="false" />
回答2:
Try the steps outlined here: http://www.mkyong.com/java/how-to-insert-a-new-line-in-resource-bundle-messages-java/
Basically, you use the StringEscapeUtils.unescapeJava(String str) static method.
来源:https://stackoverflow.com/questions/9207021/how-to-add-new-line-character-n-in-message-resource-bundle-in-jsf1-2