LoadBundle 2.x
AlexanderLitus edited this page Aug 7, 2014
·
1 revision
TOCSTART
<div>
<ul>
<li><a href="#LoadBundle2.x-CreatingtheLoadBundle">Creating the LoadBundle</a></li>
</ul>
</div>
<p>TOCEND</p>
<p>The OpenFaces <cite>LoadBundle</cite> component is used for loading a resource bundle localized for
the Locale of the current view, and expose it (as a Map) in the request attributes of the current
request. The <u><o:loadBundle></u> component is similar to the standard <u><f:loadBundle></u>
tag it but can be used in the components with Ajax enabled.</p>
<h4><a name="LoadBundle2.x-CreatingtheLoadBundle"></a>Creating the LoadBundle</h4>
<p>The usage of the OpenFaces <cite>LoadBundle</cite> component is similar to the same component from the Reference
or MyFaces JSF implementation. To add the <cite>LoadBundle</cite> component to the page, use the <u><o:loadBundle></u>
tag. This tag has only <b>var</b> and <b>basename</b> attributes. The <b>var</b> attribute specifies the name of
a request-scope variable under which the resource bundle is available. There are two ways to access keys of the
resource bundle:</p>
<ol>
<li>#{bunble.propertyKey}</li>
<li>#{bundle['propertyKey']}</li>
</ol>
<p>The <b>basename</b> attribute specifies the path to the resource bundle file. The resource bundle file should be
available in the classpath.</p>
<p>Here is an example of the resource bundle in the h:outputText component.</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<o:loadBundle basename="my.resources.TestLoadBundle" var="bundle"/> ... <h:outputText value="#{bundle.todayString}"/>
</div>
</div>
<p>In this example the resource bundle is located in WEB-INF/classes/my/resources directory. And there is a
"todayString" property key in the TestLoadBundle resource bundle.</p>
<p>In the following example the resource bundle in located in WEB-INF/classes directory and the "todayString"
property key is used.</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<o:loadBundle basename="TestLoadBundle" var="bundle"/> ... <h:outputText value="#{bundle['todayString']}"/>
</div>
</div>