How to pass parameters to an entry defined in the resource bundle

Environment (JDeveloper 11.1.2.0.0)

A validator’s error message can contain embedded expressions that are resolved by the server at runtime. This can be done easily in the model layer using named tokens delimited by curly braces as explained in  7.7.4 How to Embed a Groovy Expression in an Error Message section in developer guide. However, sometimes we need to pass a parameter to a string defined in resource bundle in the view layer. In this post I will show How to do it.

A resource bundle contains a number of named resources, where the data type of the named resources is String, and it is used to internationalize the application. I will assume that you have already defined your resource bundle and register it in the faces-config.xml as explained in Internationalizing and Localizing Pages chapter from web user interface guide.

Now suppose our resource bundle file contains this entry

#
MESSAGE=Hello {0}. You are watching {1}. Enjoy it.

you want to pass parameters  to the tokens delimited by curly braces, this can be done by using StringManger class as shown in the following method

public String PassParameterToBundle() {
// Add event code here...
String message=  oracle.jbo.common.StringManager.getString("view.ViewControllerBundle", "MESSAGE", "No matching string found",new String[]{"ADF Developer","https://mjabr.wordpress.com/"});
System.out.println("message " + message);
return message;
}

view.ViewControllerBundle in the method is the resource bundle that is registered in the faces-config.xml file as shown below

<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee">
<application>
<default-render-kit-id>oracle.adf.rich</default-render-kit-id>
<resource-bundle>
<base-name>view.ViewControllerBundle</base-name>
<var>res</var>
</resource-bundle>
</application>
</faces-config>

after executing the method you will see this message in the console: Hello ADF Developer. You are watching https://mjabr.wordpress.com/. Enjoy it.

Advertisements

Leave a comment

Filed under ADF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s