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>
MY ORIGINAL CODE WAS:
<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" />
GETTING ERROR:
Caused by: java.lang.IllegalArgumentException: unknown format type at
at java.text.MessageFormat.makeFormat(MessageFormat.java:1433)
at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
at java.text.MessageFormat.<init>(MessageFormat.java:368)
at org.displaytag.decorator.MessageFormatColumnDecorator.<init>(MessageFormatColumnDecorator.java:52)
at org.displaytag.tags.ColumnTag.addHeaderToTable(ColumnTag.java:722)
at org.displaytag.tags.ColumnTag.doEndTag(ColumnTag.java:622)
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!!
SHOULD BE:
<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" />
THE LESSON:
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
this:
default:
maxOffset = oldMaxOffset;
throw new IllegalArgumentException("unknown format type at ");
See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6481179