我应该使用<h:outputText>来打印静态文本吗?

Ral*_*lph 5 jsf-2

我应该使用<h:outputText value="static text"/>或直接写入static textxhtml文件打印文本是静态的?

示例 - 带输出文本:

<h:outputText value="User Name:"/>
<h:outputText value="#{currentUser.name}"/>
Run Code Online (Sandbox Code Playgroud)

示例 - 直接:

User Name:
<h:outputText value="#{currentUser.name}"/>
Run Code Online (Sandbox Code Playgroud)

Mat*_*ndy 8

只需将其直接写入页面而不使用outputText.你甚至可以编写没有标签的el表达式.所以你可以写:

User name: #{currentUser.name}
Run Code Online (Sandbox Code Playgroud)

如果要使用ajax更改文本,有条件地呈现文本或者要将某些样式应用于文本,则需要outputText(以及其他).

  • @Ralph:不,它**被**逃脱了.另见http://stackoverflow.com/questions/7722159/csrf-xss-and-sql-injection-attack-prevention-in-jsf/7725675#7725675 (5认同)
  • 或者当您想要禁用隐式HTML转义时. (4认同)