3

How can i make part of a value in a h:outputText Bold? i want the Name in bold:

<h:outputText value="Normal Text: #{Controller.Object.name}" />

i tried: <h:outputText value="Normal Text: <b>#{Controller.Object.name}</b>" />

got this error: "The value of attribute "value" associated with an element type "h:outputText" must not contain the '<' character." after some searches here and others pages, found that the attribute escape="false" could fix this... but doesn't make difference for me,

<h:outputText escape="false" value="Normal Text: <b>#{Controller.Object.name}</b>" />

still got the same error.

has anyone had this problem?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Igor Souza
  • 53
  • 2
  • 8

2 Answers2

5

Do you really need <h:outputText>?

In Facelets you can just use EL in template text:

Normal Text: <b>#{Controller.Object.name}</b>

If you really insist in using <h:outputText>, then you should indeed manually escape the XML entities and display it with escape="false":

<h:outputText value="Normal Text: &lt;b&gt;#{Controller.Object.name}&lt;/b&gt;" escape="false" />

This not only reads uglier, but also puts a XSS attack hole open in case #{Controller.Object.name} is a client-controlled value.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks man! but i used `h:outputText ` because i need to set `rendered` attribute on few texts... i'm trying to do this with the first way... in last case i will use the last and vulnerable way – Igor Souza Feb 10 '15 at 16:04
  • 1
    Just wrap in ``. See also http://stackoverflow.com/questions/6238016/conditionally-display-pure-html-elements – BalusC Feb 10 '15 at 16:28
0

To me, it makes much more sense to put the <p></p> inside the text in the .properties file or wherever you are defining the Controller.Object.namevalue. Much cleaner and you don't have to mess with encoding symbols.

Pere
  • 1,068
  • 12
  • 20