Pages

Thursday, March 12, 2009

Generate resource bundles for ADF

JDeveloper ADF supports the use of resource bundles for the label and tooltip values of an attribute. This attribute can exists in an ADF datacontrol class or an ADF BC object. In this blog I will show you how you can set these values manually or generate these values with ANT.
First we will do this manually. In every project you can set the resource bundle option. Default is one resource bundle per project.
Now you can open the ADF BC entity or the ADF Datacontrol class xml file and select the attribute and press the edit button. Now you can put in your value for a label or a tooltip
If you already have a resource bundle than you can select a text resource in this resource bundle
This is an example of an ADF datacontrol class file with a label property and a resource bundle definition.
We can also generate resource bundles with Ant. Steve Muench already made in 2004 a example how to do this. I changed the example a little bit so it works in 11g.
First we have to make a xml with the resource values which matches our attributes of an ADF datacontrol class or an ADF BC object .

<?xml version='1.0'?>
<Mod>
<Ent name="Data" package="nl.whitehorses.model">
<Att name="lovLabel">
<Msg label="label" tip="label in nederlands"/>
<Msg lang="en" label="label" tip="label in english"/>
</Att>
<Att name="lovValue">
<Msg label="waarde" tip="Dutch for value"/>
<Msg lang="en" label="value" tip="Engels voor waarde"/>
</Att>
</Ent>
<Ent name="Data2" package="nl.whitehorses.model">
<Att name="lovLabel">
<Msg label="label" tip="label in nederlands"/>
<Msg lang="en" label="label" tip="label in english"/>
</Att>
<Att name="lovValue">
<Msg label="waarde" tip="Dutch for value"/>
<Msg lang="en" label="value" tip="Engels voor waarde"/>
</Att>
</Ent>
</Mod>

Put your xml file with the xslt file and the ant scripts in the root folder of your model project. The xslt file will generate the java resource bundles. Change the build.properties file and set your jdeveloper 11g home. Now we can run the ant scripts. Here you can download the required files.

The generated java resourcebundle looks like this.

package nl.whitehorses.model.common;
// CODE GENERATED BY XSLT From AllMessages.xml - Do Not Edit This File.
import oracle.jbo.common.JboResourceBundle;
public class DataImplMsgBundle_en extends JboResourceBundle {
public DataImplMsgBundle_en() {
}
public Object[][] getContents() {
return super.getMergedArray(sMessageStrings, super.getContents());
}
static final Object[][] sMessageStrings = {
{"lovLabel_LABEL","label"},
{"lovLabel_TOOLTIP","label in english"},
{"lovValue_LABEL","value"},
{"lovValue_TOOLTIP","Engels voor waarde"}
};
}

You can see that label resource has the following name convention attributename_LABEL.
Now we only have to add this resource to the ADF datacontrol class xml file. Open the xml and go the structure window and a ResourceBundle element with a JavaResourceBundle child element.

That's all.

No comments:

Post a Comment