下面是delete方法的代码:
我有一个primefaces数据表,其中一列包含一个用于删除相关行的commandButton。当我对数据表进行排序并删除一行时,它会删除排序前在该位置的行。
例如,假设在数据表中有5行:line 1 with id=12
line 2 with id=10
line 3 with id=25
line 4 with id=36
line 5 with id=1
现在假设我按id对行进行排序。我得到以下行:
line 1 with id=1 (previously line 5)
line 2 with id=10 (previously line 2)
line 3 with id=12 (previously line 1) <---------------
line 4 with id=25 (previously line 3)
line 5 with id=36 (previously line 4)
到目前为止还好。
现在,如果我决定删除第3行,它将删除第1行,它位于第3行之前的位置
这是我的dataTable标签: <p:dataTable id="histoNotif" var="notif"
value="#{historiqueNotifController.listNotifications}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,20"
emptyMessage="No notifications"
rowStyleClass="#{notif.date==null ? 'new' : null}">
...
</p:dataTable>
我希望我把问题解释清楚了。谢谢你。下面是delete方法的代码:
public void delete(Notif notif) {
try {
notifService.deleteNotif(notif);
listNotifs.remove(notif);
} catch (Exception e) {
if (e instanceof DataIntegrityViolationException) {
LOGGER.error(e.getStackTrace());
}
}
}
和按钮代码:
<p:commandButton actionListener="#{notifController.delete(notif)}"
update=":formNotifs :formNotif"/>
最近遇到了这个问题,经过几个小时的尝试修复它,它最终导致我使用:
javax.faces.view.ViewScoped
我换回下面来最终解决这个问题:
javax.faces.bean.ViewScoped