dinsdag 24 november 2009

Devoxx 2009

I skipped 2008 so I can't compare with that. This year was a lot about annotations and how they make xml files redundant. In JSF 2.0 for instance the faces-config.xml is optional. Also EJBs are much easier to define and it can even be done in a single class from now on (jee6).

I'm pretty sure you can find more about this conference online.

maandag 23 november 2009

JSF: translation of messages in managed bean

In JSF managed beans you can add messages to the context for use in views. For instance when an error occurs you can add a message to be displayed to the user. This is how:

FacesContext.getCurrentInstance().addMessage(null,
    new FacesMessage("message"));

The null is an identifier you can provide in order to identify an element of the view. I don't want that kind of information in my managed bean so I left this out. But that isn't the problem. My problem is that the message wasn't translated this way. So I figured out how to get to the resourcebundle configured in the faces-context definition:

ApplicationFactory factory = 
    (ApplicationFactory) FactoryFinder
    .getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory..getApplication();
ResouceBundle bundle = ResourceBundle.getBundle(
    application.getMessageBundle());

vrijdag 20 november 2009

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:

<u>test java.util.Date</u>
<p>this is the date without outputText tag: #{helloBean.currentDate}</p>
<p>this is the date wit outputText tag: <h:outputText value="#{helloBean.currentDate}" /></p>

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;
 }

donderdag 12 november 2009

richfaces calendar tag fails when nested in paragraph tag

When nesting the richfaces calendar tag in a paragraph tag (<p>) it doesn't work anymore. For example this code:
<p>#{bundle.availabilityDate} <rich:calendar id="validUntilDate"
     required="true"
     value="#{glossaryVersionController.glossaryVersion.availabilityDate}" /></p>

resulted in the popup not showing and this javascript error on rendering the xhtml page:
Fout: obj is null
Bronbestand: http://server:port/application/a4j/g/3_3_1.GAorg/richfaces/renderkit/html/scripts/calendar.js.xhtml
Regel: 97

When this richfaces calendar tag is used outside a paragraph tag all works well.