• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<f:convertDateTime Problem

 
Markus Schmider
Ranch Hand
Posts: 128
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you add a type attribute to the f:convertDateTime and check.

type='date'
 
Markus Schmider
Ranch Hand
Posts: 128
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just tried it, the same error persists.

But many thanks for your reply.

 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 207
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Sai could be right:

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

 
Markus Schmider
Ranch Hand
Posts: 128
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic