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

时间:2015-06-15 15:20:53

标签: jsf composite-component resourcebundle properties-file

My component library directory tree is setup as the following:

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

I'd like to load the properties file within mycomponent.xhtml to use for messages. What is the proper way of doing this? Is there an f:loadbundle type of solution?

1 个答案:

答案 0 :(得分:4)

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

  • Bundle文件与复合XHTML本身放在同一(子)文件夹中。
  • Bundle文件与复合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>
相关问题