How to add new line Character ( \n ) in message resource bundle in JSF1.2

ε祈祈猫儿з 提交于 2020-06-14 04:17:45

问题


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

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