31 August, 2012

ADF : Get Key from Resource Bundle

Resource bundles contain locale-specific objects.
In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles.

This allows you to write programs that can:
    a- be easily localized, or translated, into different languages
    b- handle multiple locales at once
    c- be easily modified later to support even more locales

You can use the below code snippet to get key value from Resource Bundle

   public static FacesContext getFacesContext() {  
     return FacesContext.getCurrentInstance();  
   public static ResourceBundle getResourceBundle(String resourceBundlePath) {  
     return ResourceBundle.getBundle(resourceBundlePath, getFacesContext().getViewRoot().getLocale());  
   public static Object getResourceBundleKey(String resourceBundlePath, String key) {  
     ResourceBundle bundle = getResourceBundle(resourceBundlePath);  
     return getResourceBundleKey(bundle, key);  
   private static Object getResourceBundleKey(ResourceBundle resourceBundle, String key) {  
     Object bundleKeyValue;  
     try {  
       bundleKeyValue = resourceBundle.getString(key);  
     } catch (MissingResourceException mrExp) {  
       bundleKeyValue = key + " not found in resource bundle";  
     return bundleKeyValue;  

Import the following classes

 import java.util.MissingResourceException;  
 import java.util.ResourceBundle;  
 import javax.faces.context.FacesContext;  

Note resourceBundlePath should be the complete package name of your resource Bundle
For example demo.mah.view.ViewControllerBundle


1 comment:

  1. There's certainly a lot to find out about this subject. I love all the points you made.
    Feel free to surf my webpage : site here


How to Pass Parameters to ActionListener in ADF

In some cases, it is required to pass a value to ActionListener of ADF Button. The method that can be invoked by actionListeners has only...