You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by bu...@apache.org on 2003/08/30 20:53:23 UTC
DO NOT REPLY [Bug 22840] New: -
Table component doesn't sort fine when there are null values
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22840>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22840
Table component doesn't sort fine when there are null values
Summary: Table component doesn't sort fine when there are null
values
Product: Tapestry
Version: 3.0
Platform: All
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Other
Component: Contrib
AssignedTo: tapestry-dev@jakarta.apache.org
ReportedBy: juceri@ya.com
Compare method in DefaultComparator, inside SimpleTableColumn not set a total
order when there are null values or not comparable values, so it doesn't sort fine.
When it compares a object obj1 with a object obj2, if (obj1 isn't comparable) or
(obj2 isn't comparable) then it returns (obj1 == obj2).
I think an order musts to be setted between comparable and not-comparable values
(example: not-comparable < comparable).
For fixing it I suggest to change the compare(...) method in the
DefaultComparator class, inside the SimpleTableColumn class by the following:
public int compare(Object objRow1, Object objRow2) {
Object objValue1 = getColumnValue(objRow1);
Object objValue2 = getColumnValue(objRow2);
if (objValue1 instanceof Comparable) {
if (objValue2 instanceof Comparable) {
return ((Comparable) objValue1).compareTo(objValue2);
}
else { //Comparable > noComparable
return 1;
}
}
else {
if (objValue2 instanceof Comparable) { // noComparable < Comparable
return -1;
}
else { //neither is comparable, then check nulls
if (objValue1 == null){
if (objValue2 == null){ //both are null, then they are equals
return 0;
} else { //null < object
return -1;
}
} else {
if (objValue2 == null){ //object > null
return 1;
} else { //neither is comparable, then I compare it strings
return (objValue1.toString().compareTo(objValue2.toString()));
}
}
}
}
}