f:loadBundle |
|
The LoadBundle tag loads a resource bundle for the Locale of the
current view and stores it as a Map in request scope. This tag is useful for
internationalization (I18N) as it allows you to access your message bundle in
your JSF page.. The body content of this tag must be empty. Place this tag above
any other component tags on your document (in the head section, for instance)
and specify a variable name for the bundle.
You can then use value-binding
expressions to output localized content on your page. Note:It is possible, but
not recommended, to define resource bundle keys in a properties file that use a
dot notation, such as message. welcome=Welcome to our site!Athough this is
syntax is legal for a Java resource bundle, it is not valid for a JSF message
bundle due to expression language parsing. For JSF, the above message should be
defined as follows:welcomeMessage=Welcome to our site!
JSF Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<f:view>
<f:loadBundle basename="com.mycompany.MessageBundle" var="bundle" />
<h:outputText value="#{bundle.welcomeMessage}" />
</f:view>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.
com/mycompany/MessageBundle.properties
welcomeMessage=Welcome to our site!
HTML Output
Welcome to our site!
|