Hi,
RecordList.sort(Comparator) throws exception in SmartGWT 2.4
The method should return RecordList but it returns JavaScriptObject and throws ClassCastException. It can be fixed by the following way:
RecordList.sort(Comparator) throws exception in SmartGWT 2.4
Code:
package com.smartgwt.client.data; public class RecordList extends BaseClass implements com.smartgwt.client.data.events.HasDataChangedHandlers { ... /** * Sorts the elements of the List in place. <P> The optional comparator function should take two parameters "a" and "b" * which are the two list items to compare, and should return: <ul> <li> a value less than zero, if "a" is less than "b" * such that "a" should appear earlier in the list <li> zero, if "a" and "b" are equal <li> a value greater than zero, * if "a" is greater than "b" such that "b" should appear earlier in the list </ul> * @param comparator comparator function to use * * @return the list itself */ public native RecordList sort(JavaScriptObject self, Comparator<Record> comparator) /*-{ return self.sort(function(record1, record2) { var record1J = @com.smartgwt.client.data.Record::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(record1); var record2J = @com.smartgwt.client.data.Record::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(record2); return comparator.@java.util.Comparator::compare(Ljava/lang/Object;Ljava/lang/Object;)(record1J, record2J); }); }-*/;
Code:
public native RecordList sort(Comparator<Record> comparator) /*-{ var self = this.@com.smartgwt.client.core.BaseClass::getOrCreateJsObj()(); var res = self.sort(function(record1, record2) { var record1J = @com.smartgwt.client.data.Record::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(record1); var record2J = @com.smartgwt.client.data.Record::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(record2); return comparator.@java.util.Comparator::compare(Ljava/lang/Object;Ljava/lang/Object;)(record1J, record2J); }); return @com.smartgwt.client.data.RecordList::getOrCreateRef(Lcom/google/gwt/core/client/JavaScriptObject;)(res); }-*/;
Comment