primefaces: DataTable: draggableRows -> wrong value sent to view after reordering
1) Environment
- PrimeFaces version: 7.0.9
- Does it work on the newest released PrimeFaces version? Version? No
- Does it work on the newest sources in GitHub? (Build by source -> https://github.com/primefaces/primefaces/wiki/Building-From-Source) No
- Application server + version: WildFly 10.1.0
- Affected browsers: All
2) Expected behavior
After dragging and reordering rows in a DataTable the currently displayed value is sent to the view by an action.
3) Actual behavior
After dragging and reordering rows in a DataTable the value previously at this position is sent to the view by an action.
4) Steps to reproduce
Click on the commandButtons to confirm that “1” displays the growl message for TestValue with id 1 and so on. Reorder a row. Click on the commandButtons to confirm that the growl message displays the TestValues still in the 1,2,3 order and not in the order displayed after reordering the rows.
5) Sample XHTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>PrimeFaces Test</title>
</h:head>
<h:body>
<h1>#{testView.testString}</h1>
<h:form>
<p:dataTable value="#{testView.testValues}"
draggableRows="true"
var="testValue">
<p:column>
<h:outputText value="#{testValue.id}: "/>
<p:commandButton action="#{testView.testAction(testValue)}"/>
</p:column>
</p:dataTable>
<p:growl life="8000">
<p:autoUpdate/>
</p:growl>
</h:form>
</h:body>
</html>
6) Sample bean
package org.primefaces.test;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Named
@ViewScoped
public class TestView implements Serializable {
private String testString;
private List<TestValue> testValues;
@PostConstruct
public void init() {
testString = "Welcome to PrimeFaces!!!";
testValues = new ArrayList<>();
testValues.add(new TestValue(1));
testValues.add(new TestValue(2));
testValues.add(new TestValue(3));
}
public void testAction(TestValue testValue) {
FacesContext.getCurrentInstance().addMessage("id", new FacesMessage(testValue.toString()));
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
public List<TestValue> getTestValues() {
return testValues;
}
public void setTestValues(List<TestValue> testValues) {
this.testValues = testValues;
}
public class TestValue {
private int id;
public TestValue(int id) {
this.id = id;
}
public int getId() {
return id;
}
@Override
public String toString() {
return "TestValue{" +
"id=" + id +
'}';
}
}
}
Please see the attached test project, cloned from the primefaces-test.git. datatable-draggablerows-test.zip
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (12 by maintainers)
Commits related to this issue
- Fix #5326,#1499: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update — committed to melloware/primefaces by melloware 4 years ago
- Fix #5326,#1499,#1661: Datatable rowReorder AJAX update (#6311) * Fix #5326,#1499,#1661: Datatable rowReorder AJAX update * Fix #5326,#1499,#1661: Datatable rowReorder AJAX update * Fix #5326,#... — committed to primefaces/primefaces by melloware 4 years ago
Can you try your sample above using the trick they suggested the
<p:ajax event="rowReorder" update="@this"/>
to the datatable?