Keeping resource bundle inside ViewController project will not allow the bundle to be updated at runtime. In order to update the resource bundle at runtime without redeploying the application or without restarting the server there are few options, some of them are listed below:
1) Keep the resource bundle string in database: This is already discussed in following post.
2) Keep resource bundle in custom location on weblogic server: This method requires the path of property file to be set in setDomainEnv.cmd file as follows
set JAVA_OPTIONS=%JAVA_OPTIONS% -DpropFileLoc=C:\bundleDir\MyBundle.properties
This property can be read in bean file using
String propFilePath = System.getProperty("propFileLoc");
Now the bundle string can be read using either of following:
InputStream iStream = this.getClass().getResourceAsStream(propFilePath );
OR
InputStream iStream = new FileInputStream(propFilePath);
prop.load(iStream );
bundleText=prop.getProperty("bundleText");
The advantage of above way of accessing the bundle is that we can keep the bundle file at any custom location on the server.
3) Keep resource bundle file in Domain directory: This method does not require the setDomainEnv.cmd file to be changed. The file can directly be accessed using following code:
InputStream is=new FileInputStream("./MyBundle.properties");
Properties prop=new Properties();
prop.load(is);
prop.getProperty("bundleText");
Instead of writing bean for loading the resource bundle, we can write a servlet to read the property file and return the key value. On jspx page, the servlet can then be access from the component attributes like value or image as follow:
<af:image id="i1" source="/myServlet?propName=bundleText"/>
1) Keep the resource bundle string in database: This is already discussed in following post.
2) Keep resource bundle in custom location on weblogic server: This method requires the path of property file to be set in setDomainEnv.cmd file as follows
set JAVA_OPTIONS=%JAVA_OPTIONS% -DpropFileLoc=C:\bundleDir\MyBundle.properties
This property can be read in bean file using
String propFilePath = System.getProperty("propFileLoc");
Now the bundle string can be read using either of following:
InputStream iStream = this.getClass().getResourceAsStream(propFilePath );
OR
InputStream iStream = new FileInputStream(propFilePath);
prop.load(iStream );
bundleText=prop.getProperty("bundleText");
The advantage of above way of accessing the bundle is that we can keep the bundle file at any custom location on the server.
3) Keep resource bundle file in Domain directory: This method does not require the setDomainEnv.cmd file to be changed. The file can directly be accessed using following code:
InputStream is=new FileInputStream("./MyBundle.properties");
Properties prop=new Properties();
prop.load(is);
prop.getProperty("bundleText");
Instead of writing bean for loading the resource bundle, we can write a servlet to read the property file and return the key value. On jspx page, the servlet can then be access from the component attributes like value or image as follow:
<af:image id="i1" source="/myServlet?propName=bundleText"/>
No comments:
Post a Comment