Ahh.. I looked at the source and realized what I was doing wrong.

The way the code is written, if you pass the sort field constructor a value of 'true' for caseInsensitive then it automatically does a string compare on the field. This makes sense and is actually a good way to enforce a string compare on a data field if that is what you want. However, you just need to be careful if you accidentally put 'true' in there as you are copying and pasting code from other SortField objects... like me!

This does a String compare:
new SortField("myDate",true);

This does a Date compare:
new SortField("myDate");

- Kevin


On Nov 18, 2007, at 8:18 PM, Kevin wrote:

The docs say this about the default compare function used in
SortField assignments:

(from Class SortField )
"The default value is an internal compare function that can perform a
string, numeric, or date comparison in ascending or descending order,
with case-sensitive or case-insensitive string comparisons. Specify
your own function only if you need a need a custom comparison
algorithm."

But I have found that I must implement a custom sort function to make
sorting on a date field work. Am I doing something wrong or are the
docs mislead in saying that the default compare function can handle
date sorting?

Thanks, Kevin



Reply via email to