SeamFramework.orgCommunity Documentation
To support a more developer friendly way of handling TimeZones, in
addition to supporting JDK TimeZone
,
we have added support for using Joda-Time through their
DateTimeZone
class. Don't worry, it provides
convenience methods for converting to JDK TimeZone
.
To activate Joda-Time for i18n within your project you will need to add the following Maven dependency:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>1.6</version>
</dependency>
We have an Application time zone that is available with Joda-Time
(DateTimeZone
) or the JDK (TimeZone
)
that can be retrieved with
@Inject
private DateTimeZone applicationDateTimeZone;
@Inject
private TimeZone applicationTimeZone
It can also be accessed through EL by the name "defaultDateTimeZone" for Joda-Time or "defaultTimeZone" for JDK!
By default the TimeZone
will be set to the JVM default, unless you produce
a String annotated with @DefaultTimeZone
.
This can be achieved through either the Seam Config module or
any bean that @Produces
a method or field that matches
the type and qualifier.
This will set the application time zone to be Tijuana:
@Produces
@DefaultTimeZone
private String defaultTimeZoneId = "America/Tijuana";
In addition to the Application time zone, there is also a time zone assigned to each User Session.
@Inject
@Client
private DateTimeZone userDateTimeZone;
@Inject
@Client
private TimeZone userTimeZone;
It can also be accessed through EL using "userDateTimeZone" for Joda-Time and "userTimeZone" for JDK.
By default the DateTimeZone
and TimeZone
for a User Session is initialized to the same as the Application. However, changing
the User's DateTimeZone
and TimeZone
is a simple matter of firing an event to update it. An example
would be
@Inject
@Client
@Alter
private Event<DateTimeZone> dtzEvent;
@Inject
@Client
@Alter
private Event<TimeZone> tzEvent;
public void setUserDateTimeZone() {
DateTimeZone dtzTijuana = DateTimeZone.forID("America/Tijuana");
dtzEvent.fire(dtzTijuana);
TimeZone tzTijuana = TimeZone.getTimeZone("America/Tijuana");
tzEvent.fire(tzTijuana);
}