This advanced component creates a custom <f:loadBundle>
tag that exposes a resource bundle as a Map
.
This tag enables you to create a localizable web application. Its use is best illustrated by the following example, which shows the end result in the JSP page:
You have a standard ResourceBundle named com.foo.mypackage.resources
, and you want to use that resource bundle to localize the prompts on your JSP page. The following JSP code causes a local lookup of the locale to be performed on the value rendered by the outputText
under the message key my.message.key
.
<f:view> ... <f:loadBundle basename="com.foo.mypackage.resources" var="msgs"/> ... <h:outputText value="#{msgs['my.message.key']}"/> ... </f:view>
This JSP code works because <f:loadBundle>
synthesizes a java.util.Map
object to wrap the resource bundle, and then stores the object as a request scope attribute under the key specified by the var
attribute. Because value binding expressions know how to navigate a Map
, this technique works well for localizing things like field prompts.
In general, when you want to provide a resource bundle inside your application, you must create a properties file to contain the messages, as described in Creating and Deleting a Resource Bundle.
After you create a new properties file, it opens in the Property Editor. For each property you want to add, click New Property and, in the New Property dialog box, enter a key and a value.
When you deploy your application, the properties file is copied to the WEB-INF/classes/project-name
directory for you, so that it is available for the <f:loadBundle>
tag to load. When you use the bundle file, you specify a value for the for the basename
property of an <f:loadBundle>
tag that is the combination of the project name (same as the package name) and the properties file base name separated by a period. For example, if your project name is webapplication1
and the properties file is named Bundle
, the code is:
<f:loadBundle basename="webapplication1.Bundle" var="var-name"/>