Wednesday, February 25, 2009

Change language / Locale in ADF

Sometimes you need to support multiple languages in your ADF application. This probably means that you need to change labels, listbox values and maybe need to change the number format layout like the decimal and number grouping separator. In this example I will show you how you can achieve this. Here are some pics of the JDeveloper 11g example application I made. You can change the language by selecting an language in the listbox and press the refresh button or you can use a language.
Here we go from dutch to english.
In this example I am using resourcebundles to change the values / labels to the right language. You can use properties or java files for the resourcebundles. To use these resourcebundles in our application we have to configure this in the faces-config.xml or do this in the JSF page.
The JSF page I made for this demo

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="" version="2.1"
<c:set var="viewcontrollerBundle"
< contentType="text/html;charset=windows-1252"/>
<af:panelGroupLayout layout="horizontal">
<af:selectOneChoice label="Locale" id="choice"
<af:selectItem label="Dutch" value="nl"/>
<af:selectItem label="English" value="en"/>
<af:commandButton text="Refresh"/>
<af:spacer width="10" height="10"/>
<af:commandButton text="Dutch" disabled="#{UserPreferences.language == 'nl'}"
<af:setActionListener to="#{UserPreferences.language}" from="nl"/>
<af:commandButton text="English" disabled="#{UserPreferences.language == 'en'}"
<af:setActionListener to="#{UserPreferences.language}" from="en"/>
<af:spacer width="10" height="20"/>
<af:outputLabel value="#{viewcontrollerBundle.OUTPUT}"/>
<af:outputLabel value="#{msg.OUTPUT}"/>
<af:outputLabel value="#{jmsg.java_output}"/>
<af:outputLabel value="100000">
<af:selectOneChoice label="Label" value="2">
<af:forEach items="#{bindings.lovDataResult.rangeSet}" var="li">
<af:selectItem label="#{li.lovLabel}" value="#{li.lovValue}"/>

I use the c:set component in the JSF page to define the resourcebundle, but when you want to use this resourcebundle in more then one page you also can define this in the faces-config.xml.
Here is my faces-config.xml which I use in this demo.

<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="1.2" xmlns="">

In the faces-config we can define what our default locale is. The resourcebundle without an underscore and country code should contain the labels which matches the default locale. In this example I also support english so I need to create a or file which contain the english values. After this we need define the main resourcebundles ( without _en ) and under which variable name it is known.

Here you see an project overview of the different resourcebundles I used in this example

To format number values with the right decimal and number grouping separator we can use the trinidad-config.xml. Here we can use an EL expression to define the separator for the right Locale.

<?xml version="1.0" encoding="windows-1252"?>
<trinidad-config xmlns="">
<number-grouping-separator>#{UserPreferences.language=='nl' ? '.' : ','}</number-grouping-separator>
<decimal-separator>#{UserPreferences.language=='nl' ? ',' : '.'}</decimal-separator>

To see the effect of these separators we need to use af:convertNumber on an inputtext or an outputtext.

In the JSF and the trinidad-config.xml I use this backing bean to set or read the selected language.
In this backing bean I also call an ADF MethodAction which refreshes the listbox with the right locale values.

package nl.whitehorses.bean;


import java.util.Locale;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;

import oracle.binding.OperationBinding;

public class UserPreferences implements Serializable {

private String language;

public UserPreferences() {
language = Locale.getDefault().getLanguage();

private void changeLocale(String language){
System.out.println("changeLocale "+language);
this.language = language;
Locale newLocale = new Locale(this.language);
FacesContext context = FacesContext.getCurrentInstance();

// refresh lov method action
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding lovOper = bc.getOperationBinding("getLovData");


public void localeChangeListener(ValueChangeEvent valueChangeEvent) {

public void localeChangeListener(ActionEvent actionEvent) {

public void setLanguage(String language) {
System.out.println("setLanguage "+language);

this.language = language;

public String getLanguage() {
return language;

Here an example of a java resourcebundle.

package nl.whitehorses.locale.view;

import java.util.ListResourceBundle;

public class JavaLocale_en extends ListResourceBundle {

public Object[][] getContents() {
return contents;
private Object[][] contents =
{ { "java_output", "java output" }
, { "java_output2","java output 2" }, };

Here you can download my 11g workspace


  1. Hello Edwin,
    First, I want to thank you ,it's very useful topic, I like your blog very mush,
    but may you explain how did you full the "label Choice list" with data

    Good Man

  2. Hi Karim,

    I made a method with has a language parameter and this returns the choices in the right language. ( if you use adf bc then you can add this to the application module ) .

    Now I made method action in ADF and on this a method iterarator and I use this iterator on the choicelist.

    and when I change the locale I refreshes this iterator by executing the method action.

    thanks Edwin

  3. hai friends,
    i need to know does oracle adf support hebrew language ....
    help me out..

  4. Hi

    I am sure Oracle supports hebrew.

    thanks Edwin

  5. Hi Edwin,
    Your post working fine for me. Language and number group and dec separators i can set per session now. Could you also show how to work with date format if i want user to setup its own and different user in his sessions his own>
    Thanks in advance.


  6. Hi Edwin,
    Thanks for usefull blog.
    But i want to change Locale as user specific .I mean can i add Locale in session according to different user choice.Currently i did accoding to ur above steps but problem is, if oneof user changes the Locale it will apply to all other users.
    Can u guide me where i did a mistake.
    Thanks for all help.


  7. Hi Robert,

    you can use af:inputDate or af:inputtext with a convertor af:convertDateTime pattern="dd-MM-yyyy" this pattern can be set in a backing bean.

    hope this helps

    thanks Edwin

  8. Hi JayDeep.

    very strange the locale should only live in your session, just like the locale of your browser.

    Did you start a new browser or test one session in IE and one in firefox for example.

    Thanks Edwin

  9. Hi Edwin ,
    when i tried to run the sample you gave i got this exception :
    java.lang.ClassNotFoundException: oracle.adf.share.weblogic.listeners.ADFApplicationLifecycleListener
    at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(
    at weblogic.utils.classloaders.GenericClassLoader.findClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(

    This issue seems to be known i tried this solution but it doesn't work also :(

    thanks for your help

  10. Hi,

    you can remove it from the weblogic-application.xml.

    this file is in your application/src/meta-inf folder


  11. Can I in ADF do the following (if so how) ?

    I want some input text boxes on the UI to be dependent on a language choice list. The style/fonts/local in which a user will enter data into these should be based upon the language selected. If user selects Chinese, he should be able to enter the data in those particular text boxes in chinese. Other things on the UI however should not change.
    Please help me with this.

  12. Hi,

    I want some input text boxes on the UI to be dependent on a language choice list.

    that is possible, you can make a look and feel changer by making different css and register these in the trinidad files. and in these css you can define a chines font.

    hope this helps

  13. Hi thanks for this useful topic
    i want to change "Struts Logic Tag Library" code (greaterEqual or others ....) to Farsi can u help me plz.

  14. Hi,

    this is very nice article!! exactly what i was looking for.

    I have one more question, in my case locale is coming from a BPM process, so how can i set the default locale based on the value from BPM process before the page gets loaded.


    1. Hi,

      it depends, sometimes it uses the browser preferences and off course you can always set the java language and country on the weblogic container. I think it is and -Duser.language=en


    2. No, actually the case is there is lang prefrence variable in the BPM object, so if the value is en for that i need to set the locale to en similarly for if the value is fr i need to set locale to fr.


  15. Hi Edwin,

    I have one question regarding the locale format.

    that is, we are using BPM process to get the data from PSFT, and where we want the direct binding data to be formatted based on the formatter provided.

    In the above case the converter is not applying, it displays as string instead of number/sal. But when I gave the value as "123445"(<af:outputText value="123445"), its able to convert to the currency able to see the formated value.

    Could you please let me know what changes need to be done to use as binding values as input and format to currency/number in ADF.

    Thanks in Adv,

  16. below is the sample code which is not working:

    <af:outputText value="#{bindings.empSal.inputValue}" id="ot29">
    <af:convertNumber type="currency"/>

  17. Hi,
    Just a big thank you very much for this post, helped me in my project at crucial points, while other posts failed to be understandable! :)

  18. hi,
    Is this code is applicable in malayalam language.i tried it but,its not working properly.Could you please solve this issue.

  19. Creative blog post , I am thankful for the specifics ! Does anyone know where my business can grab a fillable a form version to fill out ?