我有一个使用rowExpansion的嵌套数据表。展开行时,会正确加载每个嵌套表的内容。但是,当过滤器应用于根表时,将加载 all 嵌套表的内容。如果有很多行,这会导致性能下降。
请注意,这不是“JSF多次调用getters”-problem。扩展行的内容缓存在后备中。它的行为就像在应用过滤器之前展开每一行一样。请注意,过滤器仅涉及“value”属性,而不是扩展内容的“字符串”。
<p:dataTable value="#{backing.elements}" var="row"
filteredValue="#{backing.elementsFiltered}">
<p:column>
<p:rowToggler />
</p:column>
<p:column headerText="Value" filterBy="#{row.value}">
<h:outputText value="#{row.value}" />
</p:column>
<p:rowExpansion>
<p:dataTable value="#{row.strings}" var="string">
<p:column headerText="Strings">
<h:outputText value="#{string}" />
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
支持bean:
@Named
@ViewScoped
public class Backing implements Serializable {
private List<Element> elements;
private List<Element> elementsFiltered;
@PostConstruct
public void init() {
// Load the list of elements.
}
public List<Element> getElements() {
return elements;
}
public List<Element> getElementsFiltered() {
return elementsFiltered;
}
public void setElementsFiltered(List<Element> elementsFiltered) {
this.elementsFiltered = elementsFiltered;
}
}
实体:
public class Element {
private String value;
private List<String> strings;
public String getValue() {
return value;
}
// This getter is called for a particular row when it is expanded.
// But it is called for all rows when the table is filtered.
public List<String> getStrings() {
if (strings == null) {
// Expensive opperation to load the strings.
}
return strings;
}
}
这是一个错误吗?或者我在这里做错了什么?
Primefaces 5.3.0,JSF 2.2,Java EE 7.0