Description
- The
- <a4j:loadBundle>
- component is similar to the same component from the JSF =
Core library. The component loads a resource bundle
- localized for the Locale of the current view and exposes it (as a Map) =
in the request attributes of the current request.
+
+ The <a4j:loadBundle> component is similar to JSF <f:loadBundle>: =
+ it loads a resource bundle localized for the Locale of the curre=
nt view and stores properties as a Map in the current request attributes of=
the current request. =
+
\ No newline at end of file
Modified: branches/community/3.3.X/docs/userguide/en/src/main/docbook/inclu=
ded/loadBundle.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/lo=
adBundle.xml 2009-07-08 19:43:43 UTC (rev 14861)
+++ branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/lo=
adBundle.xml 2009-07-09 11:16:08 UTC (rev 14862)
@@ -31,73 +31,181 @@
=
-
- Creating on a page
-
- To create the simplest variant on a page use the following synta=
x:
-
-
- Example:
- ]]>
- =
-
- =
-
- Creating the Component Dynamically Using Java
-
-
- Example: =
-
+ Creating the Component with a Page Tag
+
+ To create the simplest variant on a page use the followi=
ng syntax:
+
+
+ Example:
+
+ ]]>
+
+ =
+
+ Creating the Component Dynamically Using Java
+
+ Example:
+
+
- =
-
+...]]>
+
+ =
+
+ Details of usage
+
+ Internationalization and Localization are the processes =
of adaptation of web applications for different languages and cultures. =
+ When you develop English and German versions of a site i=
t can be said that you localize the site for England and Germany. =
+ Language is not the only thing that undergoes the locali=
zation =E2=80=94 dates, times, numbers, currencies, phone numbers, addresse=
s, graphics, icons, colors, personal titles and even favourite sounds are a=
lso varies from country to country. =
+ It means that an internationalized application may have =
lots of different type information, which should be changed depending on us=
er location. =
+
+
+ There are several approaches of organizing the localizat=
ion. =
+ The JSF <h:loadBund=
le> loads bundles into the request scope when page=
is being rendered and updates all the needed areas in a crowd. =
+ Ajax requests work in their own request scopes, so bundl=
e information loaded in such way became unavailable. =
+ The approach provided by RichFaces <a4j:loadBundle> component enriche=
s one given by the JSF <h:loadBundle&g=
t; with Ajax capability: =
+ It allows to use reference to a particular bundle item d=
uring an Ajax update.
+
+
+ Using of the <a4j:l=
oadBundle> is pretty simple. =
+ Imagine a small application that says "Hello!"=
in different languages where switching between translations (localization =
in our case) occurs on clicking the corresponding links, like you have used=
to see on lots of sites. =
+ In our JSF with RichFaces application (those who feel no=
t strong in that should better read the "Getting started with RichFaces" chapter) create resource bu=
ndles with "Hello!" message for three different languages: Englis=
h, German and Italian. =
+ Resource bundles are represented with *.properties=
extention files that keep items in Key(Name)/Value pai=
rs. =
+ A key for an item should be the same for all locales. =
+
+
+
+ Resource bundles *.properties files w=
ith Keys and Values for multi-language application. View in JBDS.
+
+
+
+
+
+
+
+
+ =D0=9Cessage resource bundles should be registered in th=
e Faces configuration (faces-config.xml) file of your applicat=
ion as <message-bundle> inside the <application=
> element. =
+ Name of a resource should be specified without language =
or country code and without .properties extension. =
+ Supported locales should be specified inside the &=
lt;supported-locale> element. =
+
+
+ Registering resource bundles in =
the Faces configuration file:
+
+
+
+ en
+ en
+ de
+ it
+
+ demo.message
+]]>
+ =
+
+ For the application we will use JSF javax.faces.co=
mponent.UIViewRoot.setLocale method that will set a needed Locale =
+ (each link will invoke corresponding method =E2=80=94 th=
ere are, off course, another ways to do that). =
+
+
+ ChangeLocale Java c=
lass with three methods for setting the correponding Locale:
+
+
- Key attributes and ways of usage
-
+ import java.util.Locale;
+ import javax.faces.context.FacesContext;
=
- <a4j:loadBundle>
- allows to use reference to bundle messages during the Ajax re-=
rendering. =
-<a4j:loadBundle>
- is a substitute for the
-<f:loadBundle>
- in JSF 1.1 which is not a JSF component originally. =
+ public class ChangeLocale {
+ public String germanAction() {
+ FacesContext context =3D FacesContext.getCurrentInstance();
+ context.getViewRoot().setLocale(Locale.GERMAN);
+ return null;
+ }
=
-<f:loadBundle>
- is a jsp tag that load the bundle messages into the request =
scope when page is rendered. As soon as each Ajax request
-works in own request scope, the bundles loaded with =
-<f:loadBundle>
- are unavailable. =
-Instead of =
-<f:loadBundle>
- that might be located anywhere on a page, the =
+ public String englishAction() {
+ FacesContext context =3D FacesContext.getCurrentInstance();
+ context.getViewRoot().setLocale(Locale.ENGLISH);
+ return null;
+ }
+ =
+ public String italianAction() {
+ FacesContext context =3D FacesContext.getCurrentInstance();
+ context.getViewRoot().setLocale(Locale.ITALIAN);
+ return null;
+ }
+}]]>
+ =
+
+ Recently, the JSP page will look as following:
+
+ =
+
+
+
+
+
+
+ ]]>
+ =
+
+ As an output we will get a simple application with English &qu=
ot;Hello!" by default. =
+ Clicking on links "De", "Eng" and "It=
" will show the messages specified within the corresponding *.pr=
operties file.
+ To reference to a particular bundle item during an Ajax update=
it is necessary to point the component(s) that shold be re-rendered (in th=
is example it is done with the help of &l=
t;a4j:commandLink>"reRen=
der" attribute).
+ The <a4j:loadBundle>=
property> should be declared inside the f:view (this does not ma=
tter when using Facelets). =
+
+ =
+
+
+ Using of the RichFaces <a4j:loadBundle> component for applicati=
on localization.
+
+
+
+
+
+
+
+
+ =
+
+ Relevant resources links
+
+ Vizit the LoadBundle page at RichF=
aces LiveDemo for additional information on the component. =
+
+
+ More useful examples and articles: =
+
+
+
+
+ loadBundle tag reference at java.sun portal;
+
+
=
- <a4j:loadBundle>
- should be declared inside the =
+
+
+ Backing a ResourceBundle with Properties File=
s at java.sun portal;
+
+
+ =
+
+
+ Internationalization and Localization of J2EE ap=
plication explains main principles of the internationalization of =
a web application;
+
+
=
- <f:view>
- (this does not matter in case on using Facelets) =
-JSF 1.2 introduces the bundle registered in the faces-config.xml. This fix=
ed the problem with =
- <f:loadBundle>
- . =
-Therefore, you can use this JSF 1.2 way to declare your bundles. =
+
+
+ one more useful tutorial e=
xplains the internationalization of a web application using JSF message res=
ource bundle;
+
+
+ =
+
+
+ Some special problem with JSF internationalization a=
nd solution from the i-coding.de portal.
+
+
=
-
-
-
- Relevant resources links
-
- On RichFaces LiveDemo page you can found som=
e additional information for <a4j:loadBundle> component usa=
ge.
-
-
- On RichFaces LiveDemo page you can fou=
nd some additional information about <=
f:loadBundle> component.
-
-
- On RichFaces LiveDemo page you can found som=
e additional information about <f:view=
> component.
-
+ =
+ =
=
=
\ No newline at end of file
--===============3089404952212273445==--