我有一個頁面,其中包含一個Hibernate實體列表,該列表在顯示頁面時動態加載。該列表用於創建DataView,該DataView用於顯示容器中列表中條目的分頁列表。列表中的每個條目都有一個刪除圖標。當按下刪除圖標時,我懶惰地刪除條目,用實體重新加載列表(將不再包含懶惰刪除條目),並重新加載容器,但條目仍在容器中,直到我重新加載整個頁面。爲什麼?Java Wicket AJAX刷新分頁DataView
public class LogPage extends ProjectPage{
@SpringBean
private LogDao logDao;
@SpringBean
private LogEntryDao logEntryDao;
private List<LogEntry> logEntryList;
private DataView<LogEntry> dataView;
private WebMarkupContainer logEntryListContainer;
public LogPage(PageParameters pp) {
super(pp);
Project activeProject = SciProSession.get().getActiveProject();
Log log = null;
if (activeProject.getLog()==null){
log = new Log(activeProject);
log = logDao.save(log);
}else{
log = activeProject.getLog();
}
logEntryList = logEntryDao.findAll();
Collections.sort(logEntryList);
logEntryListContainer = new WebMarkupContainer("logEntryListContainer");
logEntryListContainer.setOutputMarkupId(true);
dataView = (DataView<LogEntry>) new DataView<LogEntry>("logEntryDataView", new ListDataProvider(logEntryList)) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final Item<LogEntry> item) {
final LogEntry logEntry = item.getModelObject();
item.add(new Label("contents", logEntry.getContents()));
item.add(new Label("creator", logEntry.getCreator().toString()));
AjaxActionIcon deleteIcon = new AjaxActionIcon("deleteIcon", ImageIcon.ICON_DELETE){
private static final long serialVersionUID = 1L;
@Override
protected void onClick(AjaxRequestTarget target) {
LogEntry toBeRemoved = logEntryDao.reLoad(logEntry);
toBeRemoved.setDeleted(true);
logEntryDao.save(toBeRemoved);
logEntryList = logEntryDao.findAll();
target.addComponent(logEntryListContainer);
}
};
item.add(deleteIcon);
}
};
dataView.setItemsPerPage(10);
logEntryListContainer.add(dataView);
logEntryListContainer.add(new PagingNavigator("navigator", dataView));
add(logEntryListContainer);
}
}
非常感謝!清除它,然後做addAll工作! – fred
爲了記錄,實際上這是一個更好的解決方案(在onClick中): LogEntry toBeRemoved = logEntryDao.reLoad(logEntry); toBeRemoved.setDeleted(true); logEntryDao.save(toBeRemoved); logEntryList.remove(toBeRemoved); target.addComponent(logEntryListContainer); – fred