在<p:commandButton />中插入换行符

Max*_*wer 8 jsf line-breaks primefaces jsf-2

基本上我只是想在<br>这样的"value"属性中添加一个(或类似的东西)<p:commandButton>:

<p:commandButton value="#{aBean.text}" />  
<!-- #{aBean.text} returns for example "text1<br>text2" -->
Run Code Online (Sandbox Code Playgroud)

可悲的是,没有可能设定escape="false".尝试添加自定义转换器也不起作用.我没有成功,也尝试这样做:

<p:commandButton>  
     <h:outputText escape="false" value="#{aBean.text}" />  
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)

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

Bal*_*usC 13

您需要使用&#10;表示XML实体引用的内容\n.

<p:commandButton value="text1&#10;text2" style="white-space: pre;" />
Run Code Online (Sandbox Code Playgroud)

white-space: pre;是强制性的<p:commandButton>,但不是强制性的<h:commandButton>,因为PrimeFaces生成它<button type="submit"><span>而不是a <input type="submit">.