在 msg 中使用变量属性

发布于 2025-01-07 18:50:20 字数 375 浏览 1 评论 0原文

因此,我正在开发一个应用程序,并且已对其进行设置,因此以下行

<h:outputText value = "#{msg['properties.help.keys.example.text']}" />

将从属性文件中打印一些输出值。我想要的是制作它用来查找属性变量的字符串的一部分。

IE

 <h:outputText value = "#{msg['properties.help.keys.' + cc.attrs.key + '.text']}" />

其中 cc.attrs.key 是我传递到 xhtml 中的值。这可能吗?如果可以,你会怎么做?

So I am working on an app and I have it set up so the following line

<h:outputText value = "#{msg['properties.help.keys.example.text']}" />

Will print some output value from a properties file. What I want is to make part of that string it uses to find the properties variable.

I.E.

 <h:outputText value = "#{msg['properties.help.keys.' + cc.attrs.key + '.text']}" />

Where cc.attrs.key is a value I pass into the xhtml. Is this possible if so how do you do it?

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

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

发布评论

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

评论(1

晒暮凉 2025-01-14 18:50:21

您不能像这样连接 EL 表达式中的字符串。 + 在 EL 中专门用于数字的求和运算符。您需要使用 将字符串与 EL 表达式连接起来,然后再将其嵌套在另一个 EL 表达式中。连接字符串只需通过内联表达式来完成。

<c:set var="key" value="properties.help.keys.#{cc.attrs.key}.text" />
<h:outputText value="#{msg[key]}" />

在即将推出的 EL 3.0 中,将会有一个新的 EL 运算符& 用于连接 EL 表达式中的字符串。然而,在基于 XML 的视图技术中使用 & 字符作为运算符是有争议的,因为它是保留的 XML 字符,我一直在与 EL 人员讨论这一点。应该可以使用像 ct 这样的替代运算符,它与 gtlt 等一致。


更新:在 EL 3.0 中,有新的 EL 运算符 += 用于连接 EL 表达式中的字符串。然后您的用例可以按如下方式解决:

<h:outputText value="#{msg['properties.help.keys' += cc.attrs.key += '.text']}" />

You can't concatenate strings in EL expressions like that. The + is in EL exclusively a sum operator for numbers. You need to use <c:set> to concatenate strings with EL expressions before nesting it in another EL expression. Concatenating the string is then solely be done by just inlining the expression.

<c:set var="key" value="properties.help.keys.#{cc.attrs.key}.text" />
<h:outputText value="#{msg[key]}" />

In the upcoming EL 3.0, there will be a new EL operator & for concatenating strings in EL expressions. The use of the & character as operator is however discutable in XML based view technologies as it's a reserved XML character, I've been in discussion with EL guys about that. It should be possible with an alternative operator like ct which is in line with gt, lt, etc.


Update: in EL 3.0, there is the new EL operator += for concatenating strings in EL expressions. Your use case can then be solved as follows:

<h:outputText value="#{msg['properties.help.keys' += cc.attrs.key += '.text']}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文