在 msg 中使用变量属性
因此,我正在开发一个应用程序,并且已对其进行设置,因此以下行
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能像这样连接 EL 表达式中的字符串。
+
在 EL 中专门用于数字的求和运算符。您需要使用
将字符串与 EL 表达式连接起来,然后再将其嵌套在另一个 EL 表达式中。连接字符串只需通过内联表达式来完成。在即将推出的 EL 3.0 中,将会有一个新的 EL 运算符&
用于连接 EL 表达式中的字符串。然而,在基于 XML 的视图技术中使用&
字符作为运算符是有争议的,因为它是保留的 XML 字符,我一直在与 EL 人员讨论这一点。应该可以使用像ct
这样的替代运算符,它与gt
、lt
等一致。更新:在 EL 3.0 中,有新的 EL 运算符
+=
用于连接 EL 表达式中的字符串。然后您的用例可以按如下方式解决: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.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 likect
which is in line withgt
,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: