SeamFramework.orgCommunity Documentation

Seam International Module

Reference Guide

3.0.0.Alpha3


Introduction
1. Installation
2. Locales
2.1. Default Locale
2.2. User Locale
2.3. Available Locales
3. Timezones
3.1. Default TimeZone
3.2. User TimeZone
3.3. Available TimeZones
4. Messages

The goal of Seam International is to provide a unified approach to configuring locale, timezone and language. With features such as Status messages propogation to UI, multiple property storage implementations and more.

Most features of Seam International are installed automatically by including the seam-international.jar and seam-international-api.jar in the web application library folder. If you are using Maven as your build tool, you can add the following dependency to your pom.xml file:


<dependency>
    <groupId>org.jboss.seam</groupId>
    <artifactId>seam-international</artifactId>
    <version>${seam-international-version}</version>
</dependency>

Tip

Replace ${seam-international-version} with the most recent or appropriate version of Seam International.

In a similar fashion to TimeZones we have an application Locale retrieved by

@Inject

java.util.Locale lc;

accessible via EL with "defaultLocale".

By default the Locale will be set to the JVM default, unless you override the DefaultLocaleProducer Bean through XML Config. Here are a few examples of XML that can be used to define the various types of Locales that are available ...

This will set the default language to be French.


<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:s="urn:java:seam:core" 
   xmlns:lc="urn:java:org.jboss.seam.international.locale"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee 
      http://docs.jboss.org/cdi/beans_1_0.xsd">

    <lc:DefaultLocaleProducer>
        <s:specializes/>
        <lc:defaultLocaleKey>fr</lc:defaultLocaleKey>
    </lc:DefaultLocaleProducer>
</beans>

This will set the default language to be English with the country of US.


<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:s="urn:java:seam:core" 
   xmlns:lc="urn:java:org.jboss.seam.international.locale"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee 
      http://docs.jboss.org/cdi/beans_1_0.xsd">

    <lc:DefaultLocaleProducer>
        <s:specializes/>
        <lc:defaultLocaleKey>en_US</lc:defaultLocaleKey>
    </lc:DefaultLocaleProducer>
</beans>

As you can see from the previous examples, you can define the Locale with lang_country_variant. It's important to note that the first two parts of the locale definition are not expected to be greater than 2 characters otherwise an error will be produced and it will default to the JVM Locale.

To support a more developer friendly way of handling TimeZones we have incorporated the use of Joda-Time through their DateTimeZone class. Don't worry, it provides convenience methods to convert to JDK TimeZone if required.

There are currently two ways to create a message within the module.

The first would mostly be used when you don't want to add the generated message directly to the UI, but want to log it out, or store it somewhere else

@Inject

MessageFactory factory;
 
public String getMessage()
{
     MessageBuilder builder = factory.info("There are {0} cars, and they are all {1}; {1} is the best color.", 5, "green");#
     return builder.build().getText();
}

The second is to add the message to a list that will be returned to the UI for display.

@Inject

Messages messages;
 
public void setMessage()
{
     messages.info("There are {0} cars, and they are all {1}; {1} is the best color.", 5, "green");
}

Either of these methods supports the four message levels which are info, warning, error and fatal.

Both the MessageFactory and Messages classes support four ways in which to create a Message:

Examples for each of these are:

The above examples assume that there is a properties file existing at org.jboss.international.seam.test.TestBundle.properties with key1 being a simple text string and key2 including a single parameter.