如何使用outputText显示换行符? [英] How to display a line break with outputText?

查看:105
本文介绍了如何使用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="&lt;br/&gt;" 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆