h:outputText 来自资源包(属性文件)的换行符

发布于 2025-01-05 06:37:12 字数 1142 浏览 3 评论 0 原文

我试图破坏 的 value 属性内显示的文本,如果我将文本直接放置在 的 value 属性内,效果很好。 h:outputText ,但是如果我将相同的文本放入属性文件中,它就会停止工作,

这里是一个正常工作的文本示例

A<br />B<br />C

<h:outputText value="A&lt;br /&gt;B&lt;br /&gt;C" escape="false"/>

不起作用:

属性文件中的代码:

someText = A&lt;br /&gt;B&lt;br /&gt;C

我发现的唯一方法是用

 包装 标签,但这还不够好,因为它改变了文本的字体,看起来很奇怪,无论如何我希望有一种 JSF 方法可以在使用属性文件 b.tw 时实现换行符

我查看了以下内容链接,但它们对我没有好处

JSF h:outputText 字符串中长单词的换行符

在 p:commandButton 内插入换行符提前

谢谢!

I'm trying to break the text that is displayed inside the value attribute of the <h:outputText , that works fine if i place the text directly inside the value attribute of the <h:outputText , but if I place the same text inside the property file , it stop working

here is an example of the text

A<br />B<br />C

this works fine:

<h:outputText value="A<br />B<br />C" escape="false"/>

does not work:

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

code from property file:

someText = A<br />B<br />C

the only way i found is wrap the <h:outputText with a <pre> tag , but that's not good enough cause it changes the font of the text , it look weird , and any way I hope that there is a JSF way to achieve the line breaks when working with a property file

b.t.w I looked at the following links , but they are no good for me

JSF h:outputText line break for long words within strings

Insert a line break inside p:commandButton

Thanks ahead!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╭⌒浅淡时光〆 2025-01-12 06:37:12

属性文件不需要包含 XML 转义的 HTML。属性文件不像 Facelets 文件那样由 XML 解析器解析。只需将 HTML 纯文本放入属性文件中即可。

someText = A<br />B<br />C

然后您可以按照通常的方式使用

The properties files doesn't need to contain XML-escaped HTML. Properties files are not parsed by a XML parser like Facelets files. Just put the HTML plain in the properties file.

someText = A<br />B<br />C

Then you can use <h:outputText value="#{text.someText}" escape="false" /> the usual way.

毁梦 2025-01-12 06:37:12

如果您想使用格式设置,请尝试将 <:outputText escape="false" ... /> 与属性一起使用。

Try using <:outputText escape="false" ... /> with the properties, if you want to use the formatting.

悟红尘 2025-01-12 06:37:12

我面临一个类似问题:还使用属性文件中的较长文本,其中包含
未渲染,

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

而在其他一些情况下它可以工作。 ..

字符串看起来像这样:

This is a longer string, <br />that should be wrapped.

事实证明:问题不是
,而是未转义的 , - ofc。生成属性值的列表,而不是预期的文本。
以防万一有人遇到这样的事情。

I was facing a similar Issue: Also using a longer text from a property file, containing <br /> was not rendered with

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

while in some other cases it worked...

The String looked like this:

This is a longer string, <br />that should be wrapped.

As it turns out: The problem was not the <br />, but the unescaped , - ofc. that generated a List for the property value and not the expected Text.
Just in case anybody facing something like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文