| Issue 32: | sorting numbers | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Jeff, I have a column with numbers. When I sort this column I get the classic problem with a natural ordering for strings like this: 1 10 11 2 3 4 5 6 7 8 9 Is there a way to specify that this column should be ordered as numbers? Tricky part is that I am working with the jmesa tags. So far I did not need to do anything programmatically with JMesa, maybe now I do? cu, Tom
Oct 4, 2007
#1
tkalm...@gmail.com
Oct 4, 2007
Ok forgive me! I now see my "number" getter returns a String (thanks to our wonderful dba ...). You are already doing an "instanceof" somewhere appearantly, great. I still have to figure out how to order this list of Strings as numbers though :-)
Oct 4, 2007
I use the commons comparator library to do the sorting. You would have to write your
own comparator and plug it in if you wanted the API to do the sorting a different way.
However, the easiest thing to do is just write another method on your bean that
returns a number. When you specify the column property it just looks at the methods
so if you had something like:
<column property="ageInt" />
The method it looks at would be:
public int getAgeInt() {
return Integer.parseInt(this.age);
}
If you have a framework that automatically returns a domain object from your service
tier you could also consider wrapping the object in the controller and place your
method in the wrapper.
Also, if you wouldn't mind signing up for the Google Groups that would be a better
place to ask questions. The only reason I ask that is because other developers would
think to look in the groups for similar type questions. Once the problem is deemed a
bug we can move it to the issues :).
Oct 9, 2007
This is a more of a google groups post than an issue.
Status:
Invalid
|