Insert a line break inside <p:commandButton />

别来无恙 提交于 2019-12-09 05:46:36

问题


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

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?


回答1:


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

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

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



来源:https://stackoverflow.com/questions/9270293/insert-a-line-break-inside-pcommandbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!