如何缩短资源包调用?复合组件?
我对内置 JSF 资源包的可能性不太满意,例如:
<h:outputFormat value="#{messages['form.label.create']}">
因此我尝试编写自己的复合组件来缩短这些内容:
<composite:interface>
<composite:attribute name="value" />
<composite:attribute name="p1" />
</composite:interface>
<composite:implementation>
<h:outputFormat value="#{messages['cc.attrs.value']}"> //text.properties
<f:param value="#{cc.attrs.p1}" />
</h:outputFormat>
</composite:implementation>
用法:
<cc:messages value="label.name" p1="#{test}" />
但是表达式 messages['cc.attrs.value']
在资源包中查找 cc.attrs.*,而不是获取值内容。
我可以忘记我的方法吗?有谁知道如何做类似的事情?
I'm not really happy with the built-in JSF resource bundle possibilities, like:
<h:outputFormat value="#{messages['form.label.create']}">
Therefore I tried to code my own composite component to shorten these things:
<composite:interface>
<composite:attribute name="value" />
<composite:attribute name="p1" />
</composite:interface>
<composite:implementation>
<h:outputFormat value="#{messages['cc.attrs.value']}"> //text.properties
<f:param value="#{cc.attrs.p1}" />
</h:outputFormat>
</composite:implementation>
Usage:
<cc:messages value="label.name" p1="#{test}" />
But the expression messages['cc.attrs.value']
looks up in resource bundle for cc.attrs.* instead of fetching the value content.
Can I forget about my approach? Has anyone an idea how to do similar things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试改为编写
messages[cc.attrs.value]
。JSF 将
'cc.attrs.value'
解释为字符串值而不是变量名称。Try writing
messages[cc.attrs.value]
instead.JSF is interpreting
'cc.attrs.value'
as a string value not a variable name.