【问题标题】: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 类型的解决方案?
【问题讨论】:
标签:
jsf
composite-component
resourcebundle
properties-file
【解决方案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>