如何用outputText显示换行符?
我需要使用 outputText
渲染换行符,以便我可以利用 rendered
属性。我尝试过
<h:outputText value="<br/>" escape="false" />
,但它产生了异常
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
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" />
but it generated exception
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
自 Facelets 以来,这确实是无效的,因为它在 XML 中在语法上无效。您需要手动转义 XML 特殊字符,例如
<
、>
等。不过,您可以仅在模板文本中发出
,而不需要
。要有条件地渲染它,请将其包装在
中。
也是有效的,因为它不会向 HTML 发送任何内容。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.You can however just emit the
<br/>
in template text without the need for a<h:outputText>
.To render it conditionally, wrap it in for example a
<ui:fragment>
.A
<h:panelGroup>
is also valid as it doesn't emit anything to the HTML anyway.JSF PAGE
escape 应为
false
并编写 beanGetter
方法如下JSF PAGE
escape should be
false
and write the beanGetter
method as follows您可以尝试将
“
放入资源包中,然后从该资源包中获取值。”
You can try putting the
"<br />"
inside a resource bundle and then get the value from that resource bundle.