Matthias Wessendorf’s Weblog

Unified EL – Craziness when handling Strings

October 25, 2007 · Leave a Comment

Looking at a bug, I noticed some craziness is going on with the unified EL and coercion rules for String. It converts every null object to an empty String.

Take this TLD snippet from the core.tld, for the standard convertDateTime tag:

<attribute>
  <name>pattern</name>
  <required>false</required>
  <deferred-value>
    <type>java.lang.String</type>
  </deferred-value>
</attribute>

So, the pattern is String, fine. Now imagine this:

<h:inputText value="#{bean.aRegularDate}">
  <f:convertDateTime pattern="#{boundToSomeNullValue}" />
</h:inputText>

This does not display the date value. Why ?Simple. The pattern is converted to an empty String (“”) and, when pushing an empty String as the pattern to the SimpleDateFormat class, the format method returns “” as well:

SimpleDateFormat sdf = new SimpleDateFormat("");

System.out.println(sdf.format(new Date()));

For reasons like that, in Trinidad we just do this:

<attribute>
  ...
  <name>pattern</name>
  <deferred-value />
   ...
</attribute>

So, a tag like this works <tr:convertDateTime pattern=”#{boundToSomeNullValue}” />.See also this bug, which I noticed, during looking at another bug :-)

Categories: jsf · jsp · myfaces · trinidad

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment