在 <p:commandButton /> 内插入换行符

9
基本上我只是试图向<p:commandButton>的"value"属性添加一个<br>(或等效物),就像这样:
<p:commandButton value="#{aBean.text}" />  
<!-- #{aBean.text} returns for example "text1<br>text2" -->

很遗憾,无法设置escape="false"。尝试添加自定义转换器也没有成功。我也尝试过以下方法,但都没有成功:
<p:commandButton>  
     <h:outputText escape="false" value="#{aBean.text}" />  
</p:commandButton>

在我看来,添加一个简单的换行应该很容易,对吧?有人有解决方法吗?

1个回答

14
你需要使用&#10;,它代表了\n的XML实体引用。
<p:commandButton value="text1&#10;text2" style="white-space: pre;" />

white-space: pre;属性在<p:commandButton>中是必须的,但在<h:commandButton>中不是必须的,因为PrimeFaces会将<p:commandButton>生成为<button type="submit"><span>,而不是<input type="submit">


1
嗨,BalusC,[style="white-space: pre;"] 确实是我所缺少的。感谢您的快速回答! - Max Power

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接