December 24, 2013

Localization with f: loadBundle

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

And maken a child entry to the tag <application> for the used languages in the faces-config.xml as below


So, whenever the 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.