页面过期问题与后退按钮和检票口SortableDataProvider和DataTable

时间:2010-05-05 23:28:47

标签: datatable wicket

我在Wicket中遇到了SortableDataProvider和DataTable的问题。

我已经定义了我的DataTable:

IColumn<Column>[] columns = new IColumn[9];

//column values are mapped to the private attributes listed in ColumnImpl.java
columns[0] =  new PropertyColumn<Column>(new Model<String>("#"), "columnPosition", "columnPosition");  

columns[1] =  new PropertyColumn<Column>(new Model<String>("Description"), "description"); 
columns[2] =  new PropertyColumn<Column>(new Model<String>("Type"), "dataType", "dataType");

将其添加到表格中:

DataTable<Column> dataTable = new DataTable<Column>("columnsTable", columns, provider, maxRowsPerPage) {
    @Override
    protected Item<Column> newRowItem(String id, int index, IModel<Column> model) {
        return new OddEvenItem<Column>(id, index, model);
    }
};

我的数据提供商:

public class ColumnSortableDataProvider extends SortableDataProvider<Column> {  
private static final long serialVersionUID = 1L;

private List<Column> list = null;

public ColumnSortableDataProvider(Table table, String sortProperty) {
    this.list = Arrays.asList(table.getColumns().toArray(new Column[0]));
    setSort(sortProperty, true);
}

public ColumnSortableDataProvider(List<Column> list, String sortProperty) {
    this.list = list;
    setSort(sortProperty, true);
}

@Override
public Iterator<? extends Column> iterator(int first, int count) {
    /*
     first - first row of data
     count - minimum number of elements to retrieve
     So this method returns an iterator capable of iterating over {first, first+count} items
    */ 
    Iterator<Column> iterator = null;

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

                @Override
                public int compare(Column c1, Column c2) {
                    int result=1;
                    PropertyModel<Comparable> model1= new PropertyModel<Comparable>(c1, getSort().getProperty());
                    PropertyModel<Comparable> model2= new PropertyModel<Comparable>(c2, 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;
}

问题如下: - 我单击列标题按该列排序。 - 我导航到另一个页面 - 我单击Back(如果我执行相反的操作,则单击Forward) - 页面已过期。

使用PageParameters生成页面会很好,但我不知何故需要拦截sort事件。

任何指针都将非常感激。非常感谢!!

1 个答案:

答案 0 :(得分:0)

我很快就不知道可能导致这种情况的原因,但为了帮助诊断,您可能希望为org.apache.wicket.Session或更多的wicket代码启用调试日志记录。

页面的检索肯定涉及对方法的调用

public final Page getPage(final String pageMapName, final String path, final int versionNumber)

在这个类中,它有一些调试日志。

有关设置此日志记录的帮助,请查看How to initialize log4j properly?log4j的文档。