为了优化应用程序的性能,我在单行选择期间发现了数据表中的意外行为。
....
<p:dataTable
id="table"
var="object"
value="#{testBean.objects}"
rowKey="#{object.paramA}"
selectionMode="single"
selection="#{testBean.selectedObject}"
>
<p:ajax
event="rowSelect"
process="@this"
/>
....
如果我选择一行,则会调用表中所有条目的所有列的getter。为什么它的行为如此?
他们可以选择禁用这些吗?
我尝试使用不同的流程,例如&#39; @ none&#39;但是这些也禁用了selectionObject的setter。
感谢您的任何提示。
编辑: 使用Primeface 6.0; JSF 2.0; JavaSE 1.6;
EDIT2: 可执行代码
testpage.xhtml
<h:form id="form">
<p:dataTable
id="dtSelection"
var="object"
value="#{selectionTestBean.objects}"
selectionMode="single"
selection="#{selectionTestBean.selectedObject}"
rowKey="#{object.variableA}"
>
<p:ajax
event="rowSelect"
/>
<p:column headerText="Variable">
<h:outputText value="#{object.variableA}" />
</p:column>
</p:dataTable>
</h:form>
豆
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Named;
@WebSessionBean
@Named("selectionTestBean")
public class SelectionTestBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<ObjectA> objects;
private ObjectA selectedObject;
@PostConstruct
private void init() {
System.out.println("PostConstruct Bean");
this.objects = new ArrayList<ObjectA>();
for(int i=0; i<20; i++) {
ObjectA object = new ObjectA(i);
this.objects.add(object);
}
}
public List<ObjectA> getObjects() {
System.out.println("getObjects");
return this.objects;
}
public ObjectA getSelectedObject() {
System.out.println("getSelectedObject");
return this.selectedObject;
}
public void setSelectedObject(ObjectA selectedObject) {
System.out.println("setSelectedObject");
this.selectedObject = selectedObject;
}
}
对象
public class ObjectA {
private int variableA;
public ObjectA(int variableA) {
this.variableA = variableA;
}
public int getVariableA() {
System.out.println("getVariableA:"+this.variableA);
return this.variableA;
}
public void setVariableA(int variableA) {
this.variableA = variableA;
}
}
输出
// Step 1 load page
PostConstruct Bean
getSelectedObject
getObjects
getSelectedObject
getObjects
getVariableA:0
getVariableA:0
getVariableA:1
getVariableA:1
getVariableA:2
getVariableA:2
getVariableA:3
getVariableA:3
getVariableA:4
getVariableA:4
getVariableA:5
getVariableA:5
getVariableA:6
getVariableA:6
getVariableA:7
getVariableA:7
getVariableA:8
getVariableA:8
getVariableA:9
getVariableA:9
getVariableA:10
getVariableA:10
getVariableA:11
getVariableA:11
getVariableA:12
getVariableA:12
getVariableA:13
getVariableA:13
getVariableA:14
getVariableA:14
getVariableA:15
getVariableA:15
getVariableA:16
getVariableA:16
getVariableA:17
getVariableA:17
getVariableA:18
getVariableA:18
getVariableA:19
getVariableA:19
//---
//Step 2 click on row
getObjects
getObjects
getObjects
getObjects
getObjects
getVariableA:0
getVariableA:1
getVariableA:2
getVariableA:3
getVariableA:4
getVariableA:5
getVariableA:6
getVariableA:7
getVariableA:8
getVariableA:9
getVariableA:10
getVariableA:11
getVariableA:12
getVariableA:13
getVariableA:14
getVariableA:15
getVariableA:16
getVariableA:17
getVariableA:18
getVariableA:19
getObjects
getVariableA:0
getVariableA:1
getVariableA:2
getVariableA:3
getVariableA:4
getVariableA:5
getVariableA:6
getVariableA:7
getVariableA:8
getVariableA:9
getVariableA:10
getVariableA:11
getVariableA:12
getVariableA:13
getVariableA:14
getVariableA:15
getVariableA:16
getVariableA:17
getVariableA:18
getVariableA:19
getObjects
getObjects
getObjects
getObjects
getObjects
getObjects
getObjects
setSelectedObject
getObjects
getObjects
getObjects
//---
就像你在Output中看到的那样,选择会导致表中每个对象的getter。为什么?他们是否有可能阻止这些?