在< p:commandButton/>内插入换行符 [英] Insert a line break inside <p:commandButton />
问题描述
基本上,我只是想在<p:commandButton>
的值"属性中添加一个<br>
(或类似的东西),就像这样:
Basically I am simply trying to add a <br>
(or something equivalent) to the "value" attribute of a <p:commandButton>
like this:
<p:commandButton value="#{aBean.text}" />
<!-- #{aBean.text} returns for example "text1<br>text2" -->
遗憾的是,无法设置escape="false"
.尝试添加自定义转换器也不起作用.我也没有尝试过这样做,但是没有成功:
Sadly, there is no possibility to set escape="false"
. Trying to add a custom converter didn't work, either. I have, without success, also tried to do it like this:
<p:commandButton>
<h:outputText escape="false" value="#{aBean.text}" />
</p:commandButton>
我认为添加简单的换行符应该很容易,对吗?有人对此有解决方案吗?
In my opinion adding a simple line break should be easy enough, right? Does anyone have a solution for this?
推荐答案
您需要使用
,它代表\n
的XML实体引用.
You need to use
which represents the XML entity reference for \n
.
<p:commandButton value="text1 text2" style="white-space: pre;" />
white-space: pre;
在<p:commandButton>
上是强制性的,但在<h:commandButton>
上不是强制性的,因为PrimeFaces生成的是<button type="submit"><span>
而不是<input type="submit">
.
The white-space: pre;
is mandatory on <p:commandButton>
, but not on <h:commandButton>
, because the PrimeFaces one generates it as a <button type="submit"><span>
instead of a <input type="submit">
.
这篇关于在< p:commandButton/>内插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!