2010-05-05 44 views
2

我在檢票中有一個SortableDataProvider和DataTable的問題。頁面過期的問題與後退按鈕和檢票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; 
} 

的問題如下: - 我點擊列標題按該列進行排序。 - 我導航到不同的頁面 - 我點擊返回(或轉發,如果我做相反的情況) - 頁面已過期。

使用PageParameters生成頁面會很好,但我需要攔截排序事件。

任何指針將不勝感激。萬分感謝!!

+0

如果您將所有行縮進四個空格或將它們全部包裝在代碼標記中,代碼在此處佈局會更好。 – 2010-05-05 23:47:52

回答

0

我不知道什麼可能導致此問題,但爲了幫助診斷,您可能需要啓用org.apache.wicket.Session的調試日誌記錄或可能更多的檢票代碼。

頁面的檢索肯定涉及到的方法

public final Page getPage(final String pageMapName, final String path, final int versionNumber) 
在這個類

電話,它具有一定的調試日誌記錄。

有關設置此日誌記錄的幫助,請參閱How to initialize log4j properly?或文檔log4j