9

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

14

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi BalusC, the [style="white-space: pre;"] was indeed what I was missing. Thanks for the quick answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.