outputText renders date wrong?

outputText is rendering dates wrong! I created a simple testcase with some dates. The 2 lines per date should print exactly the same date because only difference is that that I’m using the outputText tag or not. Like this:

test java.util.Date

this is the date without outputText tag: #{helloBean.currentDate}


this is the date wit outputText tag:


It’s always the line without outputText tag that is printing just fine. Problem only occured when fetching a date from database. Like DB2 and HSQLDB.

test simple util.Date
this is the date without outputText tag: Fri Nov 20 13:40:17 CET 2009
this is the date wit outputText tag: 20-nov-2009

test with db2
this is the date without outputText tag: 2009-06-23
this is the date wit outputText tag: 22-jun-2009

test sql.date
this is the date without outputText tag: 2009-11-20
this is the date wit outputText tag: 20-nov-2009

test other db (hsqldb) date
this is the date without outputText tag: 2009-11-20
this is the date wit outputText tag: 19-nov-2009

Code used in bean:

public Date getHSQLDBDate() throws Exception {
Date date = null;
Class.forName("org.hsqldb.jdbcDriver");
Connection connection = DriverManager.getConnection(
"jdbc:hsqldb:mem:test", "sa", "");
try {
Statement statement = connection.createStatement();
try {
try {
statement.execute("drop table test");
} catch (Exception e) {
// ignore
}
statement.execute("create table test (adate date)");
PreparedStatement pstat = connection
.prepareStatement("insert into test(adate) values(?)");
pstat.setDate(1, new java.sql.Date(Calendar.getInstance()
.getTime().getTime()));
pstat.execute();
ResultSet set = statement
.executeQuery("select adate from test");
try {
if (set.next()) {
date = set.getDate("adate");
}
} finally {
set.close();
pstat.close();
}
} finally {
statement.close();
}
} finally {
connection.close();
}

return date;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait