5

Should I use <h:outputText value="static text"/> or directly write static text into the xhtml file to print text that is static?

Example - with output text:

<h:outputText value="User Name:"/>
<h:outputText value="#{currentUser.name}"/>

Example - directly:

User Name:
<h:outputText value="#{currentUser.name}"/>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ralph
  • 118,862
  • 56
  • 287
  • 383

1 Answers1

8

Just write it directly into the page without the outputText. You even can write el expressions without a tag. So you could write:

User name: #{currentUser.name}

The outputText is needed (among others) if you want to change the text with ajax, render it conditionally or if you want to apply certain styles to the text.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • 4
    Or when you want to disable implicit HTML escaping. – BalusC Mar 28 '12 at 18:22
  • An `#{currentUser.name}` without `h:outputText` does not escape the content, right? – Ralph Mar 28 '12 at 20:26
  • 5
    @Ralph: no, it **is** escaped. See also http://stackoverflow.com/questions/7722159/csrf-xss-and-sql-injection-attack-prevention-in-jsf/7725675#7725675 – BalusC Mar 29 '12 at 02:22