Sunday, September 9, 2012

Oracle ADF : Model and View Controller Resource Bundle

In any web application we need to define labels, hints , tooltips and more. Also our application may be deployed for multiple languages users. In ADF we can achieve having bundle for each language.

Example :-

English :- Model_En.properties , ViewController_En.properties

Spanish :- Model_Sp.properties , ViewController_Sp.properties

It will be easy to dynamically switch from one bundle to another during run time.

1. Create Fusion Project and create EO/VO , We don’t see any resource bundle here.

image

2. By Default attribute name will come as label , Until we override this value.

image

3. Override the label in the control hints property of attribute , We can use any EO/VO to give control hint , but I prefer to use EO.

image

If we give this value and click OK , it will create following resource bundle file.

image

 

View Controller Bundle

In Product list page we will place some button and name it as “Create New” label which will come from view controller bundle.

Right click view controller project properties and set the following value in Resource Bundle

image

Select the command button and select following

image

Give following value and don’t forget to select View-Controller Bundle.

image

 

ViewController bundle contains following properties

image

To refer this value use

#{viewcontrollerBundle['hasim.createrow']} which will print Create Row.

This bundle is loaded in JSF with following JSF Tag.

image

Putting view controller bundle in faces-config.xml

Instead of giving above JSF tag in all JSPX pages , we should generalize this definition ,so that we don’t have to provide this tag on every JSF pages.

open face-config.xml and enter following properties in faces-config.xml

image

We can see we are referring our variable as bundle which is pointing to our view controller bundle.

Now comment the JSF tag referring to bundle.

image

Now click expression builder

image

Now you will see it is visible in following window.

image

Just click this which will automatically populate the expression part.

Enjoy !

1 comment: