ajaxKeys with sortable dataTable problem
nickthomson May 1, 2009 6:19 AMI'm using ajaxKeys on a dataTable to control which rows are reRendered after an update. I have it working fine with a standard table and even with pagination using the datascroller.
However, when I use the sorting capabilities of the dataTable, the rows do not highlight properly. I'm guessing this is because they are in a different order to the list I store the data in and therefor the wrong indexes are being returned.
My data table in my test app looks like this:
<rich:dataTable id="testDataTable" value="#{testBean.data}" var="data" ajaxKeys="#{testBean.ajaxKeys}" sortMode="single">
<rich:column sortBy="#{data.id}" sortOrder="#{testBean.orderID}" id="pid" style="#{data.viewing ? 'background: red' : '' }">
<f:facet name="header">
<h:outputText value="ID"/>
</f:facet>
<a4j:commandLink style="display: block; width: 100%;" action="#{testBean.SelectView(data)}" value="#{data.id}" reRender="pid,param1"/>
</rich:column>
<rich:column sortBy="#{data.testParam1}" sortOrder="#{testBean.orderParam1}" id="param1" style="#{data.viewing ? 'background: red' : '' }">
<f:facet name="header">
<h:outputText value="Param 1"/>
</f:facet>
<a4j:commandLink style="display: block; width: 100%;" action="#{testBean.SelectView(data)}" value="#{data.testParam1}" reRender="pid,param1"/>
</rich:column>
</rich:dataTable>
And the appropriate parts of the backing bean:
private List<TestData> data = new ArrayList<TestData>();
private TestData selectedItem = null;
private HashSet<Integer> ajaxKeys = new HashSet<Integer>();
public void SelectView(TestData data) {
this.ajaxKeys.clear();
this.ajaxKeys.add(this.data.indexOf(this.selectedItem));
this.selectedItem.setViewing(false);
this.selectedItem = data;
this.selectedItem.setViewing(true);
this.ajaxKeys.add(this.data.indexOf(this.selectedItem));
System.out.println(this.ajaxKeys.toString());
}
public TestData getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(TestData selectedItem) {
this.selectedItem = selectedItem;
public Set<Integer> getAjaxKeys() {
return this.ajaxKeys;
}
Anyone have any suggestion how to fix this?
Thanks.