Richfaces 数据表在排序后为 rowclick 事件返回错误的行。例如:test.xhtml
<rich:dataTable id="testId" value="#{testBean.names}" var="name">
<a4j:ajax event="rowclick" listener="#{testBean.selectName(name)}" />
<rich:column id="name" sortBy="#{name}" sortOrder="#{testBean.nameOrder}">
<f:facet name="header">
<a4j:commandLink value="Name" execute="@this" render="testId" action="#{testBean.sortByName}" />
</f:facet>
<h:outputText value="#{name}" />
</rich:column>
</rich:dataTable>
TestBean.java
public class TestBean {
private List<String> names;
private SortOrder nameOrder = SortOrder.unsorted;
public TestBean() {
names = new ArrayList<>(Arrays.asList("BBBB", "AAAA", "DDDD", "CCCC"));
}
public List<String> getNames() {
return names;
}
public void selectName(final String name){
System.out.println(name);
}
public void sortByName() {
if (nameOrder.equals(SortOrder.ascending)) {
setNameOrder(SortOrder.descending);
} else {
setNameOrder(SortOrder.ascending);
}
}
public SortOrder getNameOrder() {
return nameOrder;
}
public void setNameOrder(SortOrder nameOrder) {
this.nameOrder = nameOrder;
}
}
如果你运行上面的代码,你会看到当你点击第一行“AAAA”时,它会打印控制台“BBBB”。当我在萤火虫上检查它时,我注意到行索引与单元格索引不匹配。
<tr id="**page:testId:0**" class="rf-dt-r rf-dt-fst-r" onclick="RichFaces.ajax(this,event,{"parameters":{"javax.faces.behavior.event":"rowclick","org.richfaces.ajax.component":"page:testId"} ,"sourceId":this} )">
<td id="**page:testId:1:name**" class="rf-dt-c">AAAA</td>
</tr>
它是富人的一个错误吗?有人可以帮助解决这个问题吗?