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

Posted

技术标签:

【中文标题】如何在复合组件中加载资源包属性文件?【英文标题】:How can I load a resource bundle properties file within a composite component? 【发布时间】:2015-08-31 04:05:25 【问题描述】:

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

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

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

【问题讨论】:

【参考方案1】:

复合材料通过#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>

【讨论】:

以上是关于如何在复合组件中加载资源包属性文件?的主要内容,如果未能解决你的问题,请参考以下文章