如何在复合组件中加载资源包属性文件?

How can I load a resource bundle properties file within a composite component?

我的组件库目录树设置如下:

resources
    mylib
        css
            mycomponent.css
        properties
            mycomponent.properties
        mycomponent.xhtml

我想在 mycomponent.xhtml 中加载属性文件以用于消息。这样做的正确方法是什么?有 f:loadbundle 类型的解决方案吗?

复合材料通过 #{cc.resourceBundleMap} 隐式支持资源包。这只需要:

  • 捆绑文件放置在与复合 XHTML 本身相同的(子)文件夹中。
  • 捆绑文件与复合 XHTML 本身具有完全相同的文件名(前缀)。

所以,如果你稍微重组一下,

WebContent
 |-- resources
 |    `-- mylib
 |         |-- mycomponent.css
 |         |-- mycomponent.properties
 |         `-- mycomponent.xhtml
 :

那么您应该可以访问它,如下所示:

<cc:implementation>
    <h:outputStylesheet library="mylib" name="mycomponent.css" />
    ...
    <p>Property with key "foo": #{cc.resourceBundleMap.foo}</p>
    <p>Property with key "foo.bar": #{cc.resourceBundleMap['foo.bar']}</p>
</cc:implementation>