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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…