返回按钮和小门SortableDataProvider和DataTable的页面过期问题 [英] Page expired issue with back button and wicket SortableDataProvider and DataTable

查看:158
本文介绍了返回按钮和小门SortableDataProvider和DataTable的页面过期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经将DataTable定义为:

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

//列值映射到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){
返回新的OddEvenItem< Column>(id,index,model);
}
};

我的数据提供者:

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

私人列表<列> 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<?扩展列>迭代器(int first,int count){
/ *
首先 - 第一行数据
计数 - 要检索的元素的最小数量
所以这个方法返回一个能够迭代的迭代器超过{first,first + count}项目
* /
迭代器<列> iterator = null;

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

@Override
public int compare(列c1,列c2){
int result = 1;
PropertyModel< Comparable> model1 = new PropertyModel< ;可比性>(c1,getSort());
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

返回结果;
}
});
}

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

返回迭代器;
}

问题如下:
- 我点击列标题按列排序。
- 我导航到不同的页面
- 我点击返回(或转发,如果我做相反的情况)
- 页面已过期。



使用PageParameters生成页面很好,但我以某种方式需要拦截排序事件来执行此操作。



任何指针都将不胜感激。感谢一下!!

解决方案

我不清楚可能是什么原因造成的,但为了帮助诊断,您可能需要启用 org.apache.wicket.Session 的调试日志记录,或可能更多的检票口代码。



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

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

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



有关设置此日志记录的帮助,请查看如何正确初始化log4j? log4j 的文档。


I've got an issue with SortableDataProvider and DataTable in wicket.

I've defined my DataTable as such:

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");

Adding it to the table:

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);
    }
};

My data provider:

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;
}

The problem is the following: - I click a column header to sort by that column. - I navigate to a different page - I click Back (or Forward if I do the opposite scenario) - Page has expired.

It'd be nice to generate the page using PageParameters but I somehow need to intercept the sort event to do so.

Any pointers would be greatly appreciated. Thanks a ton!!

解决方案

I don't know at a quick glance what might be causing this, but in order to help diagnose, you might want to enable debug logging for org.apache.wicket.Session or possibly more of the wicket code.

The retrieval of a page definitely involves calls to a method

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

in this class, and it has some debug logging.

For help with setting up this logging, have a look at How to initialize log4j properly? or at the docs for log4j.

这篇关于返回按钮和小门SortableDataProvider和DataTable的页面过期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆