Skip to main content

Accessing Resource Bundles from a ViewObject

There were couple of threads in ADF BC discussion forums asking for APIs to access associated resource bundle from a ViewObject/EntityObject class. One possibility is to use standard java.util.ResourceBundle API. Another interesting approach is to make use of the oracle.jbo.common.StringManager APIs used by the ADF BC layer. This is a wrapper over standard java ResourceBundle class.

The below method is based on the second approach. This help you to retrieve the value for a key from the resource bundle associated with a ViewObject.

    public String getLocalizedValue(String key) {

        ResourceBundleDef resourceDef = this.getResourceBundleDef();
        Locale locale = this.getApplicationModule().getSession().getLocale();
        String retVal =
            StringManager.getLocalizedStringFromResourceDef(resourceDef, key,
                                                            false);
        return retVal;
    }

Where can I see the reference for the 'ResourceBundle' in a ViewObject?

<ResourceBundle> element in the ViewObject's XML definition references the associated resource bundle file.
<ViewObject ....>
......
 <ResourceBundle>
    <PropertiesBundle
      PropertiesFile="model.ModelBundle"/>
  </ResourceBundle>
</ViewObject>

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS2 + HR Schema]

This sample tries to initialize the DepartmentName with a value from the resource bundle that is associated with Department ViewObject. You can see that 'DepartmentsViewRowImpl' java file contains the above mentioned getLocalizedValue(...) method. This method is referred through groovy expression adf.object.getLocalizedValue("DEFULT_DEPT_NAME") specified against DepartmentName in the DepartmentsView.


Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html

Comments

Anonymous said…
I have a question. The above approach assumes that the resource bundle is within the jar file which is not usually the case. If I have to change a label value, I will have to redeploy the jar file. Is there a way to specify a properties file that is outside of a jar and I still have control as to where the properties file is located?

Thanks
Harish said…
Hi Jobinesh,

Since you are an authority on ADF I was wondering if you could help me resolve my issue.

Problem Statement:
1. I have a simple fusion application with Model and view controller.
2. The model as well as view controller project has one resource bundle each.

Question 1:
I would like to customize a resource bundle present in Model/View Controller Project (i.e change a key value with out changing the key value in the original project)value.

Couple of Ways in which I did this:
Approach 1:
Created resource bundles with the same name as present in Model/ViewController and deployed it as a shared library and referred it in the applications weblogic-application.xml

Problem with the above approach:
1. I have to maintain a copy of every single key in the shared library even though I need to change only few values:

Approach 2:
a)Create a resource bundle with just the values I would like to customize.
b) Deploy it as a shared library
c) Write a bean which checks for the key in the shared resource bundle and if it doesnt find it , then look for the same key in the project's resource bundle.

Issues:
Cant use this approach to customize resource bundle present in Model project.

Note: I know it is possible to do achieve some of this using MDS, but I want to stay clear from it.

So what I am looking at:
1. Easier way to change label values for both Entity/View(jspx) objects with out changing the base resource bundle.
2. I would like to avoid the whole redudant key issue which I mentioned earlier and just be able to change the key whose values I would like to change.

Any help in this regard would be highly appreciated.

Thanks and Regards
Harish

Popular posts from this blog

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…