Daniel
Daniel

Reputation: 37051

h:outputText with line break from resource bundle (properties files)

I'm trying to break the text that is displayed inside the value attribute of the <h:outputText , that works fine if i place the text directly inside the value attribute of the <h:outputText , but if I place the same text inside the property file , it stop working

here is an example of the text

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

this works fine:

<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 property file:

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

the only way i found is wrap the <h:outputText with a <pre> tag , but that's not good enough cause it changes the font of the text , it look weird , and any way I hope that there is a JSF way to achieve the line breaks when working with a property file

b.t.w I looked at the following links , but they are no good for me

JSF h:outputText line break for long words within strings

Insert a line break inside p:commandButton

Thanks ahead!

Upvotes: 5

Views: 8003

Answers (3)

dognose
dognose

Reputation: 20889

I was facing a similar Issue: Also using a longer text from a property file, containing <br /> was not rendered with

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

while in some other cases it worked...

The String looked like this:

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

As it turns out: The problem was not the <br />, but the unescaped , - ofc. that generated a List for the property value and not the expected Text. Just in case anybody facing something like this.

Upvotes: 0

BalusC
BalusC

Reputation: 1108642

The properties files doesn't need to contain XML-escaped HTML. Properties files are not parsed by a XML parser like Facelets files. Just put the HTML plain in the properties file.

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

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

Upvotes: 10

premma
premma

Reputation: 373

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

Upvotes: 1

Related Questions