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

811 views Asked by At

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

There are 1 answers

0
BalusC On BEST ANSWER

Composites have implicit support for resource bundles via #{cc.resourceBundleMap}. This only prerequires:

  • Bundle file is placed in same (sub)folder as composite XHTML itself.
  • Bundle file has exactly the same filename (prefix) as composite XHTML itself.

So, if you restructure a bit,

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

Then you should be able to access it as below:

<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>