如何缩短资源包调用?复合组件?

发布于 2025-01-08 22:04:54 字数 766 浏览 4 评论 0原文

我对内置 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 技术交流群。

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

发布评论

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

评论(1

一个人的旅程 2025-01-15 22:04:54

尝试改为编写 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.

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