There are two ways to load the properties file into JSF 2.0.
- Global Resource Bundle To load the properties file globally, so that all the jsf pages can access the messages. You can create a “faces-config.xml” file and declare the properties file explicitly.
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<resource-bundle>
<base-name>com.mkyong.messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
Option 2: Local Resource Bundle
To load the properties file locally, or for specified page only. Declare the <f:loadBundle />
tag in the page that need to access the message in the messages.properties.
Out of these two which one gives me better performance?
Lets say I going with 1st option, does it means all the bundles gets loaded during the application startup or is it lazy loading? (on demand)
If choose a 2nd option, does it potentially cause bundle to get loaded multiple time for each ViewRoot?
Is the Java ResourceBundle is factory class which provides singleton object within servlet container?
I mean getBundle method is factory method which creates singleton object for always?
ResourceBundle myResources =
ResourceBundle.getBundle("MyResources", currentLocale);
Lets say I have a page abc.xhtml and I am using f:loadBundle, and there 1000 users accessing this page, does this mean there would 1000 resouceBundle object created? or is it only object which is being shared by all the page instances?