【问题标题】:Insert a line break inside <p:commandButton />在 <p:commandButton /> 中插入换行符
【发布时间】:2012-03-05 10:21:42
【问题描述】:

基本上,我只是想将&lt;br&gt;(或等效的东西)添加到&lt;p:commandButton&gt; 的“值”属性中,如下所示:

<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>

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

【问题讨论】:

    标签: jsf jsf-2 primefaces line-breaks


    【解决方案1】:

    您需要使用&amp;#10;,它代表\n 的XML 实体引用。

    <p:commandButton value="text1&#10;text2" style="white-space: pre;" />
    

    white-space: pre;&lt;p:commandButton&gt; 上是强制性的,但在 &lt;h:commandButton&gt; 上不是强制性的,因为 PrimeFaces 将其生成为 &lt;button type="submit"&gt;&lt;span&gt; 而不是 &lt;input type="submit"&gt;

    【讨论】:

    • 嗨 BalusC,[style="white-space: pre;"] 确实是我所缺少的。感谢您的快速回答!
    猜你喜欢
    • 2014-01-09
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多