Primefaces datatable onEdit() edits the wrong entry if an entry has been added before refreshing the view

风格不统一 提交于 2019-12-25 06:13:11

问题


i've got a question concerning Primefaces (version 5.0) and their datatable. If I have a p:datatable and I want to edit a cell or row (doesn't matter - behaviour is the same in that case) AND someone added a new entry to that database, I edit the new entry instead of the old.

Well. Here are some code-snippets:

my index.xhtml:

<h:form id="viewChanges">
  <p:dataTable id="changeTable" 
             widgetVar="changeTable"
             value="#{changeController.list}" var="item"
             selection="#{changeController.selectedChangeEntry}"
             selectionMode="single" rowKey="#{item.id}"
             sortBy="#{item.id}" sortOrder="descending"
             editable="#{lDAPUserController.loggedIn}" 
             style="width: auto">

                <p:ajax event="rowEdit" 
                        listener="#{changeController.onRowEdit}" 
                        update=":growlInfo, :growlError, :viewChanges:changeTable" />

                         ..output of columns..

                <p:column style="width:32px">
                    <p:rowEditor />
                </p:column>
  </p:dataTable>
</h:form>

my changeController.java

@ManagedBean(name = "changeController")
@ViewScoped
public class ChangeController implements java.io.Serializable {

    attributes, getter, setter, other methods etc..

    public void onRowEdit(RowEditEvent event) { 
        FacesMessage msg = new FacesMessage("Change Edited", ((Change) event.getObject()).getId());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}

Well with this it's already possible to replicate the error. Little Example: We have a dataset with 3 entries. - id=1,2,3

We open a browser[1] and see the 3 datasets. We now open a private tab[2] and go to the same site and add a new entry. Without refreshing [1] we edit the entry with id=3. All of the sudden we edited entry with id=4.

Could someone explain me why this is happening? Is it me or is it bug in primefaces? Wrong Scope?

来源:https://stackoverflow.com/questions/30917122/primefaces-datatable-onedit-edits-the-wrong-entry-if-an-entry-has-been-added-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!