这是我的代码:
SortablePlayerDataProvider dp = new SortablePlayerDataProvider();
final DataView<Player> dataView = new DataView<Player>("rows", dp, 10) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final Item<Player> listItem) {
final Player player = listItem.getModelObject();
listItem.setModel(new CompoundPropertyModel<Player>(player));
listItem.add(new Label("name", player.getName()));
listItem.add(new Label("surname", player.getSurname()));
listItem.add(new Label("club", player.getClub()));
}
};
和提供者:
public class SortablePlayerDataProvider extends SortableDataProvider<Player> {
private static final long serialVersionUID = 1L;
public SortablePlayerDataProvider() {
setSort("surname", SortOrder.ASCENDING);
}
@Override
public Iterator<Player> iterator(int first, int count) {
return tournamentService.getAllPlayer().subList(first, first + count).iterator();
}
@Override
public int size() {
return tournamentService.getAllPlayer().size();
}
@Override
public IModel<Player> model(final Player object) {
return new LoadableDetachableModel<Player>() {
private static final long serialVersionUID = 1L;
@Override
protected Player load() {
return object;
}
};
}
}
但排序不起作用,我不知道为什么。怎么了 ?是否有 som optins 如何调试它?
更新:
有人可以解释一下并显示这个 dataProvider 排序项目在哪里吗?
因为当我打印它时:
Iterator<Player> a = dp.iterator(0, dp.size());
for (Iterator<Player> iterator = a; iterator.hasNext();) {
System.out.println(iterator.next());
}
项目仍然没有排序,当我寻找这个提供者的实现时,我找不到这个迭代器在哪里排序。