This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes <f:convertDateTime Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "<f:convertDateTime Problem" Watch "<f:convertDateTime Problem" New topic
Author

<f:convertDateTime Problem

Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 100
A JEE6/JSF 2.0/JPA 2.0 application running on JBoss 6 M5.



Bean:


The converter works fine, however when I save the entity to a database (MySQL) and load it again, one month has been miraculously substracted from the date
e.g 05/10 -> 04/10. The date in the database is correct (2010-05-01).
Of course when I save again, the date in the database will be wrong.

What's going on here?
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 199
    
    1

Can you add a type attribute to the f:convertDateTime and check.

type='date'
Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 100
I have just tried it, the same error persists.

But many thanks for your reply.

Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 199
    
    1

Okie looks like this is the problem ----
Basically, for JSF DateTimeConverter Javadoc states that if the timeZone attribute is not specified, then the default is GMT.
But when you create an instance of java.text.SimpleDateFormat, the default TimeZone is equal to TimeZone.getDefault() which in your case might not be GMT and thats the reason of the offset.
Enrique Villamizar
Ranch Hand

Joined: Jul 30, 2005
Posts: 93
I think Sai could be right:

So adds to the page and in the back Bean (yourBean):

Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 100
Yes the timezone did it.
Many thanks.

However i still think this behavior is strange because the offset between GMT and CET is one hour and not one month
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 199
    
    1

The only way I can think of this is probably the date comes back as 2010-05-01 with time defaulted to 00:00:00 hours. Now since CET runs behind GMT, it is still 2010-04-30. Probably, That is why the month offset.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <f:convertDateTime Problem
 
Similar Threads
opening a website in my own application(how do i render it properly?)
Wierd problem while using valueChangeListener() during submit of a form
strange error for displaying date
question on datetime converter and validation of a datetime field
Weird Conversion Error inputText behavior with Dates