H: outputText with line break from resource bundle (property files)

I am trying to break the text that appears inside the value <h:outputText , which works fine if I put the text directly inside the value <h:outputText , but if I put the same text inside the properties file it stops working

here is a sample text

 A&lt;br /&gt;B&lt;br /&gt;C 

this works great:

 <h:outputText value="A&lt;br /&gt;B&lt;br /&gt;C" escape="false"/> 

does not work:

<h:outputText value="#{text.someText}" escape="false"/>

code from the properties file:

 someText = A&lt;br /&gt;B&lt;br /&gt;C 

the only way i found is to wrap <h:outputText with a <pre> , but that is not very good because it changes the font of the text, it looks weird and somehow I hope there is a JSF way to achieve the gap lines when working with a properties file

btw I looked at the following links, but they do not suit me

JSF h: line break outputText for long words inside lines

Insert line break inside p: commandButton

Thanks in advance!

+4
source share
3 answers

Property files must not contain HTML-escaped HTML. Property files are not processed by the XML parser, such as Facelets files. Just put the HTML file in the properties file.

 someText = A<br />B<br />C 

Then you can use <h:outputText value="#{text.someText}" escape="false" /> usual way.

+8
source

Try using <:outputText escape="false" ... /> with properties if you want to use formatting.

+1
source

I ran into a similar problem. Also, using longer text from a properties file containing <br /> was not displayed with

 <h:outputText value="#{text.someText}" escape="false" /> 

while in some other cases it worked ...

The line looked like this:

 This is a longer string, <br />that should be wrapped. 

As it turned out: the problem was not <br /> , but unscreened , - ofc. which created a list for the value of the property, not the expected text. Just in case, someone is faced with something like that.

0
source

Source: https://habr.com/ru/post/1396352/


All Articles