public final class OnSortEventListener implements EventListener, Serializable {
private static final long serialVersionUID = 1L;
@Override
public void onEvent(Event event) throws Exception {
final Listheader lh = (Listheader) event.getTarget();
final String sortDirection = lh.getSortDirection();
if ("ascending".equals(sortDirection)) {
final Comparator<?> cmpr = lh.getSortDescending();
if (cmpr instanceof FieldComparator) {
String orderBy = ((FieldComparator) cmpr).getOrderBy();
orderBy = StringUtils.substringBefore(orderBy, "DESC").trim();
// update SearchObject with orderBy
getSearchObject().clearSorts();
getSearchObject().addSort(orderBy, true);
}
} else if ("descending".equals(sortDirection) || "natural".equals(sortDirection) || Strings.isBlank(sortDirection)) {
final Comparator<?> cmpr = lh.getSortAscending();
if (cmpr instanceof FieldComparator) {
String orderBy = ((FieldComparator) cmpr).getOrderBy();
orderBy = StringUtils.substringBefore(orderBy, "ASC").trim();
// update SearchObject with orderBy