SeamFramework.orgCommunity Documentation
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.
Starting at the application level the module provides a DateTimeZone
that can be retrieved with
@Inject
DateTimeZone applicationTimeZone;
It can also be accessed through EL by the name "defaultTimeZone"!
By default the TimeZone
will be set to the JVM default, unless you override the DefaultTimeZoneProducer
Bean using the Seam Config module.
For instance, adding this XML into seam-beans.xml
or beans.xml
will change the default TimeZone
of the application to be Tijuana!
<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:tz="urn:java:org.jboss.seam.international.timezone"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://docs.jboss.org/cdi/beans_1_0.xsd">
<tz:DefaultTimeZoneProducer>
<s:specializes/>
<tz:defaultTimeZoneId>America/Tijuana</tz:defaultTimeZoneId>
</tz:DefaultTimeZoneProducer>
</beans>
We also have a DateTimeZone
that is scoped to the User Session which can be retrieved with
@Inject
@UserTimeZone
DateTimeZone userTimeZone;
It can also be accessed through EL using "userTimeZone".
By default the TimeZone
will be the same as the application when the User Session is initialised. However, changing
the User's TimeZone
is a simple matter of firing an event to update it. An example would be
@Inject
@Changed
Event<DateTimeZone> tzEvent;
public void setUserTimeZone()
{
DateTimeZone tijuana = DateTimeZone.forID("America/Tijuana");
tzEvent.fire(tijuana);
}