在< p:commandButton/>内插入换行符 [英] Insert a line break inside <p:commandButton />

查看:102
本文介绍了在< 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?

推荐答案

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

You need to use &#10; which represents the XML entity reference for \n.

<p:commandButton value="text1&#10;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">.

这篇关于在&lt; p:commandButton/&gt;内插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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