Up/down sorting doesn't work on wicket - AjaxFallBackTable

I have a problem with Ajaxfallbacktable - the pagenation is working fine - the data loading - everything is easy as pie - even the default sorting works - but I can't figure out how to add updown buttons in every column - so that I can sort the table anyway I want Here is my table

List<IColumn<logParsed>> columns = new ArrayList<IColumn<logParsed>>();

columns.add(new PropertyColumn<logParsed>(new Model<String>("Number of Entries"), "numberOfEntries") {
    @Override
    public String getCssClass()
    {
        return "numeric";
    }
});
columns.add(new PropertyColumn<logParsed>(new Model<String>("Last Seen"), "lastSeen"));
columns.add(new PropertyColumn<logParsed>(new Model<String>("Host Name"), "hostName") {
    @Override
    public String getCssClass()
    {
        return "hostname";
    }
});
columns.add(new PropertyColumn<logParsed>(new Model<String>("Log Message"), "logMessage"));


logProvider<logParsed> LogProvider = new logProvider<logParsed>(logParsedDao.findAll());
final AjaxFallbackDefaultDataTable<logParsed> dataTable = new AjaxFallbackDefaultDataTable<logParsed>("table", columns, 
        LogProvider, 10) {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    protected Item<logParsed> newRowItem(String id, int index, IModel<logParsed> model) {
        return new OddEvenItem<logParsed>(id, index, model);
    }
};

/* add(new OrderByBorder("sortByHighest", "numberOfEntries", LogProvider)
{
    private static final long serialVersionUID = 1L;

    @Override
    protected void onSortChanged()
    {
       dataTable.setCurrentPage(0);
    }
}); */
add(dataTable);

Here is my dataprovider:

public class LogProvider<logParsed> extends SortableDataProvider{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private LogParsedDao logParsedDao;





private List<logParsed> list =  new ArrayList<logParsed>();

public LogProvider(List<logParsed> sentList){

    setSort("numberOfEntries",SortOrder.DESCENDING);
    list = sentList;
}

public Iterator iterator(int first, int count) {

    //ArrayList<logParsed> newList = (ArrayList<logParsed>) logParsedDao.findAll();
    //Collections.sort(newList, comparator);
    Iterator<logParsed> iterator = null;

    try {
        if(getSort() != null) {
            Collections.sort(list, new Comparator<logParsed>() {
                private static final long serialVersionUID = 1L;

                    public int compare(logParsed sl1, logParsed sl2) {
                     int result=1;
                        PropertyModel<Comparable> model1= new PropertyModel<Comparable>(sl1, getSort().getProperty());
                        PropertyModel<Comparable> model2= new PropertyModel<Comparable>(sl2, getSort().getProperty());

                        if(model1.getObject() == null && model2.getObject() == null) 
                            result = 0;
                        else if(model1.getObject() == null) 
                            result = 1;
                        else if(model2.getObject() == null) 
                            result = -1;
                        else 
                            result = ((Comparable)model1.getObject()).compareTo(model2.getObject());

                        result = getSort().isAscending() ? result : -result;

                        return result;
                }
            });
        }

        if (list.size() > (first+count))
            iterator = list.subList(first, first+count).iterator();
        else
            iterator = list.iterator();
    } 
    catch (Exception e) {
        e.printStackTrace();
    }

    return iterator;

}

public int size() {
    // TODO Auto-generated method stub
    return list.size();
}

public IModel model(final Object object) {
    return new AbstractReadOnlyModel<logParsed>() {
        @Override
        public logParsed getObject() {
            return (logParsed) object;
        }
    };
}

}

Answers


Use the PropertyColumn constructor that receives the sort property: PropertyColumn(displayModel, sortProperty, propertyExpression).


Need Your Help

PHP Cryptography Good Practices?

php cryptography

So I heard md5() and sha1() are both outdated and potentially broken. I've heard that crypt() isn't a viable solution as well.

Authenticate jquery-mobile app with json backend (making API)

javascript php jquery json

For my php-web-app I use ajax calls to populate content.