Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i show text with html tag in primefaces

I get a String from < p:editor> like this : < b>This is bold text< /b>. I want to show <b>This is bold text</b> in xhtml page. What tag can i use to do that ?

like image 636
xuanhung2401 Avatar asked Oct 22 '11 09:10

xuanhung2401


1 Answers

Use an outputText with escape="true":

<h:outputText escape="true" value="<b>This is bold</b>"/>

As stated in the answer to this question:

...Facelets implicitly wraps inline [emphasis added] content in a component as represented by <h:outputText>

So, if you don't use an outputText tag with the escape attribute set to true Facelets will add one for you which will escape the html tags.

Edit: I am completely wrong about the escape attribute. Please forgive my ignorance as I am still learning as well. According to the documentation the escape attribute:

Flag indicating that characters that are sensitive in HTML and XML markup must be escaped. This flag is set to "true" by default.

Please see the answer to this OS question for a correct example.

like image 75
Jonathan Spooner Avatar answered Nov 24 '22 01:11

Jonathan Spooner