Environment (JDeveloper 22.214.171.124.0, ADF BC)
Everybody knows how to internationalize his application at run time, for those who don’t know how to do this, they can check this document. However this can be done for labels, headers text,static LOV,…etc. The question is how can we internationalize model driven LOV or dynamic LOV, this example will explain one method to do this.
Use Case: our application supports two locales Arabic (ar) and English (en), and the user has the flexibility to change his locale at run time. In our application we have a registration form page which has a Bank attribute, this form based on RegDetails view, the Bank attribute will be populated from model drivel LOV, the lookup view that populate the Bank field has this structure in database.
CREATE TABLE BANKS
( id number(10),
english_name varchar2(50) ,
CONSTRAINT bank_pk PRIMARY KEY (id)
So when the user select Arabic locale at run time, arabic_name filed should be the display value in the Bank attribute in our form, and when the user change to English locale, english_name filed should be the display value in the Bank attribute in our form.
How to implement this use case:
Fortunately ADF BC allows us to define more than one LOV for a single attribute, and switch between them as your case need. The following steps show how can we implement this, supposed that our BC has been created in advance:
- Open RegDetails entity object, to add a transient attribute called userLocale. This attribute will hold two values ar (for Arabic loacle) and en (for English locale), and this attribute is set at run time.
- Open RegDetails view object, and add the previous attribute to your view object.
- Now we need to define Bank LOV, open RegDetails view, then expand the attributes and select the Bank attribute. once you select the Bank attribute you will see List of values: Bank section, click the green plus sign to add a new LOV. The Create list of value window will be shown on your screen.
- Give a meaningful name for your LOV, select your data source or add a new one if you don’t have, select your List attribute as shown below.
- In the same window, click the UI Hints tab, and from the available area select ArabicName and shuttle it the to selected area as show below.Press OK to close the window.
- Repeat steps 3-5, to create another LOV, give it en_LOV_Bank name, and in step 5 select EnglishName instead of ArabicName as the display value.
- In RegDetails view add a new transient attribute BankLovSwitcher, The value of this attribute should contain the LOVs name which are created in the previous steps.
- Select your BankLovSwitcher attribute, and click edit (pencil symbol) to open Edit Attribute: BankLovSwitcher window. In the Value Typefield select expression radio button, and in the value field click the edit button as shown below.
- After you click the edit button, the Edit Expression builder window will be shown, enter the following expression
if(UserLocale==’ar’) return ‘ar_LOV_Bank’
else if(UserLocale==’en’) return ‘en_LOV_Bank’
and in the available area select the the UserLocale attribute and shuttle it to the selected area as shown below, then press OK.
- Now, select your Bank attribute, in the List of Values: Bank section, and from the List of Values Switcherlist select BankLOVSwitcher attribute. and select your default LOV as shown below.
- Now, all you need in your application is to add a simple method, this method should set the UserLocale attribute to ar when the user select or click the Arabic locale and set it to en when the user change to English locale.