如何使用outputText显示换行符? [英] How to display a line break with outputText?
问题描述
我需要使用outputText
渲染换行符,以便可以利用属性rendered
.我尝试过
I need to render a line break using outputText
so that I can utilize the rendered
attributed. I tried
<h:outputText value="<br/>" escape="false" />
但是它产生了异常
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
推荐答案
自Facelets以来,这确实是无效的,因为它在XML上在语法上是无效的.您需要手动转义<
,>
等XML特殊字符.
That's indeed not valid since Facelets because it's syntactically invalid in XML. You'd need to manually escape the XML special characters like <
, >
and so on.
<h:outputText value="<br/>" escape="false" />
但是,您只需在模板文本中发出<br/>
即可,而无需<h:outputText>
.
You can however just emit the <br/>
in template text without the need for a <h:outputText>
.
<br/>
要有条件地进行渲染,请将其包装在例如<ui:fragment>
中.
To render it conditionally, wrap it in for example a <ui:fragment>
.
<ui:fragment rendered="#{bean.rendered}"><br /></ui:fragment>
<h:panelGroup>
也有效,因为它仍然不会向HTML发出任何东西.
A <h:panelGroup>
is also valid as it doesn't emit anything to the HTML anyway.
<h:panelGroup rendered="#{bean.rendered}"><br /></h:panelGroup>
这篇关于如何使用outputText显示换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!