Java Reference
In-Depth Information
Locales and Character Encodings
We can be more specific when configuring locales with the
LocalePicker.Locales parameter by appending a country to the
language. For example, fr_FR and fr_CA both designate French
while distinguishing between France and Canada. We can also
append a variant: es_ES_Traditional indicates traditional Spanish
from Spain. Again, refer to the java.util.Locale Javadocs for com-
plete information on these parameters.
At the end of a locale, we can also append a colon ( : ) and
indicate a character encoding. For example, de:UTF-8 specifies
the German locale with UTF-8 character encoding.
In
JSPs,
we
can
specify
the
character
encoding
with
the
pageEncoding= attribute of the page directive:
<%@page pageEncoding="UTF-8" %>
A top-level <s:layout-definition> JSP is a good place for setting
the character encoding for all JSPs.
This is configured with the Stripes filter's LocalePicker.Locales parameter
in web.xml :
Download email_20/web/WEB-INF/web.xml
<filter>
<filter-name> StripesFilter </filter-name>
<filter-class>
net.sourceforge.stripes.controller.StripesFilter
</filter-class>
<!-- other init params... -->
<init-param>
<param-name> LocalePicker.Locales </param-name>
<param-value> en,fr </param-value>
</init-param>
</filter>
Now, if a user accesses the application with French as their preferred
language, Stripes will use the French locale and therefore the Stripes-
Resources_fr.properties file. Right now it won't find it and fall back on
StripesResources.properties , still showing the application in English! So,
the next step is to create the StripesResources_fr.properties file and learn
what keys Stripes uses when searching for localized values.
Let's use the Login page as an example. After submitting the page with
an existing primary email but with an incorrect password, you get the
screen shown in Figure 11.1 , on the next page.
 
 
Search WWH ::




Custom Search