在JSF中用不可破坏的空间替换空间 [英] Replace spaces with nonbreakable spaces in JSF

查看:154
本文介绍了在JSF中用不可破坏的空间替换空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些JSF 2.1.29建议.我对bean的属性进行了以下使用:

I need some JSF 2.1.29 advise. I have the following using of the bean's property:

#{someBean.someProperty}

#{someBean.someProperty}返回7 8的位置(请注意数字之间的空格数).在浏览器中,它仅显示为7 8.当我将这些空格替换为 时,它们将按原样显示:

Where #{someBean.someProperty} returns 7 8 (note the number of spaces between the digits). And in the browser it's displayed as just 7 8. When I replace those spaces with  , then they are displayed as is:

7      8 

我怎样才能真正显示为7 8?

How can I get to actually display as 7 8?

推荐答案

这是HTML转义功能,默认情况下启用.使用escape属性将其禁用:

That is HTML escaping at work, which is enabled by default. Disable it using the escape attribute:

<h:outputText escape="false" value="#{backingBean.someText}"/>

我刚刚对此进行了测试,当后备bean返回7&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp8时,它会输出7 8.

I just tested this, and it outputs 7 8 when the backing bean returns 7&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp8.

或者,使用 CSS空白属性保留普通的(不间断的)空白:

Alternatively, use the CSS white-space property to preserve plain (not non-breaking) white spaces:

<h:outputText value="#{backingBean.someText}" style="white-space: pre"/>

CSS解决方案通常更好,因为它可以保持XSS保护.

The CSS solution is often better, as it maintains XSS protection.

  • JSF 2.0 component to interpret String with HTML code
  • Display element as preformatted text via CSS

这篇关于在JSF中用不可破坏的空间替换空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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