Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...