Thursday, January 18, 2007

Accessing property file entry from ADF Faces bean

In some cases, developer need to access property file entries not only from expression language, but also from ADF Faces Backing or Managed bean code. There is nothing difficult, just notice, that message bundle must be specified in faces-config.xml

You can download sample application -, which shows how I'm accessing property file entries from Backing bean methods. There are two buttons on the application page and one text component. Entries in property file:
  1. firstAction=First action processed
  2. secondAction=Second action processed
Value for text component is retrieved from property file and depends on clicked button:

When developing described functionality, at first I have declared message bundle in faces-config.xml:
  1. Open faces-config.xml in JDeveloper
  2. Select Overview tab
  3. Choose Application option
  4. Declare property file in Message Bundle field (e.g. lt.andrejusb.resources.UIResources)
Second step was to create two af:commandButton components along with one af:outputFormatted, for both buttons action methods in Backing bean were generated. Code for action methods:

Entries in property file are accessed using function from JSFUtils class - getStringFromBundle(param). This become possible, after declaring message bundle in faces-config.xml. JSFUtils class source comes with standard JDeveloper sample application - SRDemo.


Jorge Newton said...

Thank you for the article, this helped me a lot.

from Venezuela,

Til said...

thanks a lot but the link for the application is not working .

thanks in advance .

Dinesh said...

Hi Andrejus,

I need your help on the below scenario:

I need a variable which is visible all through the application.
I tried with sessionScope but I'm losing the value when the control goes from one ViewController project to another.

I think I cant use the property file since the value in it needs to be changed.

Could you please give your suggestions.


Andrejus Baranovskis said...

May be you can use Application Scope?


Dinesh said...

Hi Andrejus,

Thanks for the reply.

I too tried with the applicationScope but still when the control goes from one View Controller to another, I lost the value.


Andrejus Baranovskis said...

Then you can use DB as repository store.


Dinesh said...
This comment has been removed by the author.
Dinesh said...

Hi Andrejus,

I'll try with the DB.
Thank you.


Juergen said...

I can't access the zipped application to see in which directory you store the property file.

Andrejus Baranovskis said...

This is quite old post... sorry I don't have this sample anymore...


AjAiN said...

is it possible to read value from an external property file.

as requirement is client want to keep property file at seperate place(due to several perprod/prod server).

so using class loader i am trying to read external property file, i added file name in weblogic classpath in commEnv.cmd file also but not able to load property file from there.

any help?

Thanks in advance!!

Apoorv Jain

Andrejus Baranovskis said...

Yes, instead of using property file, you should use Java class for resource bundle. You can initialize it from any external file.

Andrejus said...

Hi Andrejus,

Is it possible to read a property file (which is not part of Adf app. package)from ADF

Scenaio:I need a propery file which will be outside Adf app. If i want to make some changes i will make it in property file .so that each time if there is any changes i don't require to create EAR again for deployment.

Thanks in advance