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

wsa*_*ton 3 jsf resourcebundle properties-file composite-component

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

resources
    mylib
        css
            mycomponent.css
        properties
            mycomponent.properties
        mycomponent.xhtml
Run Code Online (Sandbox Code Playgroud)

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

Bal*_*usC 5

组合通过#{cc.resourceBundleMap}. 这只需要:

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

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

WebContent
 |-- resources
 |    `-- mylib
 |         |-- mycomponent.css
 |         |-- mycomponent.properties
 |         `-- mycomponent.xhtml
 :
Run Code Online (Sandbox Code Playgroud)

然后你应该可以访问它,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)