A Date object internally always store its value as UTC (number of milliseconds from January 1, 1970 00:00:00 GMT), so it carries no timezone information. When creating a Date istance from a string rapresentation, a GMT correction is applied as the date is assumed to be expressed in the local timezone (the system default one). For example, if system timezone is GMT+1 (Rome), the date is stored subtracting one hour from the given one. This correction is also done by JDBC behind the scenes if your date is coming from a database.
To display the correct date, the same timezone has to be applied in order to have this correction "reversed". But the JSF convertDateTime (f:convertDateTime) converter uses the GMT timezone by default, leaving the Date with a correction that is the inverse of the system timezone.
Using the sandbox converter (s:convertDateTime) the system default timezone (not the request one, which is tied to the user's browser settings) will be picked. So, as long as the creation of the Date and its displaying happen on the same system, or two system with the same default timezone, the Date will be displayed as the original one. This also applies if you try to print your dates with <h:outputText value="My date is {#bean.myDate}/>, because in this way the .toString() method is called on the Date object, and this uses the system default timezone. Note that if timezones are different, a completly meaningless value is displayed.
Alternatively, you can use f:convertDateTime setting the timeZone attribute to the system default timezone used to create the Date instance (hardcoded in jsp page or storing this value in some managed bean property).
Another solution is to register the s:convertDateTime (or your implementation) as the default converter, putting this in faces-config.xml:
<converter>
<converter-for-class>java.util.Date</converter-for-class>
<converter-class>org.apache.myfaces.custom.convertDateTime.DateTimeConverter</converter-class>
</converter>
Cosma
On 5/11/06,
Cosma Colanicchia <[EMAIL PROTECTED]> wrote:
Hey you're right, my outputText is doing wrong, inputDate is displaying the correct date! :)
I've also found this FAQ on the same problem http://wiki.apache.org/myfaces/FAQ#Date , sorry for asking again. I think I'll try the default converter way, I don't like to specify timezones in all of my outputText or defining a property on all my beans.
Thanks for the precious help Volker
CosmaOn 5/10/06, Volker Weber < [EMAIL PROTECTED]> wrote:Hi Cosma,
Cosma Colanicchia wrote:
> Thank you Volker,
>
> I've read the discussion and the JIRA issue, but I'm still not sure about a
> solution. I'm using a recent snapshot of myfaces-impl-1.1.4 and a snapshot
> of tomahawk-1.1.2, so it should be already addressed in my lib version
> ([#MYFACES-506] is marked as fixed in 1.1.1), isn't it?
>
> Do I have to pass a timeZone="something" to workaround this issue?
Yes the solution was adding a
<f:dateTimeConverter timeZone="#{bean.timeZone}" />
to the t:inputDate
The problem is this:
the spec says the default timezone for a dateTimeConverter is GMT.
if no converter is explicit specified a default converter is taken to
convert java.util.Date values, which is the case at the t:inputDate.
if you use a Date as value for a h:outputText the default converter is
also taken, and the date shoult rendered equal to the inputDate tag.
But if you use value="the date is #{bean.date}." at the h:outputText,
then the value type of the _expression_ is String and the date part is not
converted by a converter (just a toString() is done)!
e.g.
<h:outputText value="The date is #{bean.date}" />
<h:outputText value="The date is "/><h:outputText value="#{ bean.date}"/>
this two lines renders the same text with (if your servers default
timezone is != GMT) different times.
Regards,
Volker
>
> Thank you again
> Cosma
>
>
> On 5/10/06, Volker Weber <[EMAIL PROTECTED]> wrote:
>
>>
>> Hi,
>>
>> see
>> http://issues.apache.org/jira/browse/MYFACES-506
>>
>> and this thread
>>
>> http://www.mail-archive.com/[email protected]/msg09779.html
>>
>> Hope this helps.
>>
>>
>> Regards,
>> Volker
>>
>>
>> Cosma Colanicchia wrote:
>> > Hi,
>> > I'm using the <t:inputDate> component, but it is rendered always a
>> > day-after the actual value of bound property. I use the component this
>> way:
>> >
>> > <t:inputDate id="birthDate" value="#{peopleAction.person.birthDate }"
>> > required="true" type="date" popupCalendar="true"/>
>> >
>> > the bound variable is of type java.util.date. I'm sure that the
>> > component is wrong because I tried to render, near the inputDate, an
>> > inputText for the same property and this one renders the correct date.
>> > What's wrong?
>> >
>> > TIA, Cosma
>>
>> --
>> Don't answer to From: address!
>> Mail to this account are droped if not recieved via mailinglist.
>> To contact me direct create the mail address by
>> concatenating my forename to my senders domain.
>>
>
--
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

