Some time we have requirement without changing the ear file need to get the some values dynamically. Examples like some URL, or some values.
For this kind of requirement we need to use external property file concept, so dynamically the application fetch the values from file how ever the values are updated in the file.
Here I am posting the steps to achieve this requirement.
First create application, after that set the some properties in view project, like below.
Next set the below code snippet in faces-config.xml file.
<resource-bundle>
<base-name>nhs.esr.view.MyResourceBundle</base-name>
<var>viewcontrollerBundle</var>
</resource-bundle>
Next we need to access the external file which stored in wls server home. And access the file in our application.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.ListResourceBundle;
import java.util.Properties;
public class MyResourceBundle extends ListResourceBundle {
private static final Object[][] contents = { };
// public Object[][] getContents() {
// return contents;
// }
public Object[][] getContents() {
//Object[][] data = null;
try {
//Property file path in system
Properties prop = new Properties();
String WL_HOME = System.getenv("WL_HOME");
prop.load(new FileInputStream(WL_HOME +
"/MyResourceBundle.properties"));
// String nodeProFile =
// "C:\\Users\\Eshwar\\Desktop\\MyResourceBundle.properties";
// System.out.println("nodeProFile : " + nodeProFile);
// load a properties file
// prop.load(new FileInputStream(WL_HOME+"/MyResourceBundle.properties"));
Enumeration propKeys = prop.keys();
System.out.println("Property size : " + prop.size());
//System.out.println("the value is :" + prop.getProperty("KEY_NAME"));
int i = 0;
while (propKeys.hasMoreElements()) {
String key = (String)propKeys.nextElement();
String value = prop.getProperty(key);
System.out.println("Key " + key + " -> : " + value);
contents[i][0] = key;
contents[i][1] = value;
i++;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return contents;
}
}
Happy learning.. :)
For this kind of requirement we need to use external property file concept, so dynamically the application fetch the values from file how ever the values are updated in the file.
Here I am posting the steps to achieve this requirement.
First create application, after that set the some properties in view project, like below.
Next set the below code snippet in faces-config.xml file.
<resource-bundle>
<base-name>nhs.esr.view.MyResourceBundle</base-name>
<var>viewcontrollerBundle</var>
</resource-bundle>
Next we need to access the external file which stored in wls server home. And access the file in our application.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.ListResourceBundle;
import java.util.Properties;
public class MyResourceBundle extends ListResourceBundle {
private static final Object[][] contents = { };
// public Object[][] getContents() {
// return contents;
// }
public Object[][] getContents() {
//Object[][] data = null;
try {
//Property file path in system
Properties prop = new Properties();
String WL_HOME = System.getenv("WL_HOME");
prop.load(new FileInputStream(WL_HOME +
"/MyResourceBundle.properties"));
// String nodeProFile =
// "C:\\Users\\Eshwar\\Desktop\\MyResourceBundle.properties";
// System.out.println("nodeProFile : " + nodeProFile);
// load a properties file
// prop.load(new FileInputStream(WL_HOME+"/MyResourceBundle.properties"));
Enumeration propKeys = prop.keys();
System.out.println("Property size : " + prop.size());
//System.out.println("the value is :" + prop.getProperty("KEY_NAME"));
int i = 0;
while (propKeys.hasMoreElements()) {
String key = (String)propKeys.nextElement();
String value = prop.getProperty(key);
System.out.println("Key " + key + " -> : " + value);
contents[i][0] = key;
contents[i][1] = value;
i++;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return contents;
}
}
Happy learning.. :)

