On Wed, 2007-12-26 at 10:45 +0800, Joe Black wrote:
>  Hi,
> 
> 
> I am using:-
> 
> myfaces-1.2.1-SNAPSHOT
> 
> Tomcat 6.0.14
> 
> Fedora Linux
> 
> java 1.6.0_02
> 
> tomahawk 1.1.6
> 
> 
> I am extracting the data from my database and diplay on the page,
> which includes one Date field as follows:- 
> 
>  
> 
> <h:dataTable
> 
>  value="#{hrHandler.allLeaveRecords}"
> 
>  var="record"
> 
>  columnClasses="columnOdd,columnEven"
> 
> binding="#{hrHandler.leaveRecordsDataTable}">
> 
>  
> 
>  
> 
> ...
> 
>  
> 
>  <h:column>
> 
>  <f:facet name="header">
> 
>  <h:commandLink
> 
>     id="dateFrom"
> 
>    actionListener="#{hrHandler.sort}">
> 
>     <h:outputText value="Date"/>
> 
>  </h:commandLink>
> 
>  </f:facet>
> 
>  <h:outputText value="#{record.dateFrom}">
> 
>     <f:convertDateTime pattern="dd-MMM-yyyy"/>
> 
>  </h:outputText>
> 
>  </h:column>
> 
>  
> 
>  <h:column>
> 
>  <f:facet name="header">
> 
>     <h:outputText value="From"/>
> 
>  </f:facet>
> 
>  <h:outputText value="#{record.dateFrom}">
> 
>     <f:convertDateTime pattern="HH:mm"/>
> 
>  </h:outputText>
> 
>  </h:column>
> 
>  
> 
> The time is earlier by 8 hours compared to the data extracted from the
> database. It also happens that the my location is GMT+8. I am not sure
> whether it is related to this.
> 
> However, if I use the JSF 1.2_07 Reference Implementation, it shows
> correctly.
> 
> Can anybody guide me whether it is my configuration problem or the
> bug?

Hmm..what you see (8 hours difference) is what I would expect, and I'm
surprised the Sun RI does what you report it does.

The JSF specification states quite clearly that the f:convertDateTime
will use UTC (ie GMT).  See the docs for method getTimeZone here:
http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/api/javax/faces/convert/DateTimeConverter.html

A Date object is theoretically always in UTC (GMT).

The f:convertDateTime therefore accepts the Date object as being in GMT
already, and performs no adjustments as its default behaviour is to
render the Date in GMT (ie in the timezone it is already in). 

What I suspect is happening, therefore, is that when creating the Date
object from the database the correct timezone mapping is occurring -
your database date is in GMT+8, but the code is correctly causing this
to be moved backwards 8 hours to make the Date object contain the
equivalent value in the normalised GMT zone. But because you have not
specified a timezone on the f:convertDateTime component, it is
outputting this value as expected - in GMT.

The f:convertDateTime component has an optional timeZone attribute; I
suggest you try setting that to the timezone in which you want the value
to be interpreted.

The tomahawk sandbox has an s:convertDateTime component that uses the
timezone of the server on which the code is deployed as the default
timezone rather than GMT. This is good for small "intranet" apps, but
can be a bad thing for apps that are intended to support users in
multiple timezones.

Why the Sun RI would do what you expect I do not know...

Regards,

Simon

Reply via email to