November 23, 2012

f: loadBundle tag


To implement localization in ADF applications, we create property files with the fields and their values in different languages. For example, I have below property file with some fields and their values in Danish language. I want to display these values in the jsf page to the user.

BODY              =Hoveddel
ITEM               =Varepost
SUBMIT          =Indsend
SUMMARY     =Oversigt
COPY               =Kopier

To use these property fields and to display on the jspx/jsff page, we were provided a tag called “loadBundle” whose syntax is as below.

<f:loadBundle basename="application" var="app"/>

Where “application” is the basename of the property file and “app” is the variable name to be used in the jspx/jsff page to invoke these fields of the property file. If you are using more property files for different language like French,English and Danish, then the property file names should be as follows.

application_fr.properties
application_en.properties
application_da.properties

So, whenever the browser language is changed, the corresponding property file will be picked up to display the fields.
And to use the fields in the page, we use el expression syntax like #{app.BODY}
In the loadBundle tag, for the basename attribute, we can also pass the ResourceBundle class instead of property file name.