Friday, 18 June 2010

"java.lang.IllegalArgumentException: unknown format type at" when using 'format' in displaytag ()

I spent about an hour stuck on this problem, so hopefully this it
helps someone avoid that. =)

We've started using the displaytag library on our JSP pages, and I was
moving a table to use this, and it makes the page much more concise
and readable, but I was getting an error when I started using the
format attribute in <display:column>


<display:column property="expiryDate" title="Expiry Date"
format="{0,expiryDate,dd/MM/yyyy}" group="2" sortable="true"
headerClass="sortable" />
<display:column property="endDate" title="End Date"
format="{0,endDate,dd/MM/yyyy}" group="3" sortable="true"
headerClass="sortable" />


Caused by: java.lang.IllegalArgumentException: unknown format type at
at java.text.MessageFormat.makeFormat(
at java.text.MessageFormat.applyPattern(
at java.text.MessageFormat.<init>(
at org.displaytag.decorator.MessageFormatColumnDecorator.<init>(
at org.displaytag.tags.ColumnTag.addHeaderToTable(
at org.displaytag.tags.ColumnTag.doEndTag(

At first I thought it was something related to the Locale that I had,
that maybe the JDK was defaulting to US Locale and maybe I should be
setting it to Australia. But I realised this wasn't the case because
the example war file with example-format.jsp had exactly this date
format and it didn't set the locale at all and was displaying fine on
my Tomcat instance.

Started playing around with the date itself then changed it to "date"
instead of the name of the property and it worked!!


<display:column property="expiryDate" title="Expiry Date"
format="{0,date,dd/MM/yyyy}" group="2" sortable="true"
headerClass="sortable" />
<display:column property="endDate" title="End Date"
format="{0,date,dd/MM/yyyy}" group="3" sortable="true"
headerClass="sortable" />


When using "format" atribute in <display:column> of displaytag,
remember: "date" should *always* be used, since in the format
attribute it is a hardcoded value, not something to match to the
property name.

NOTE: Googling the above error message reveals it's actually a JDK
bug, as the error message should be reporting the POSITION of the
unknown format type, but at the moment MessageFormat class just has

maxOffset = oldMaxOffset;
throw new IllegalArgumentException("unknown format type at ");