【发布时间】:2019-01-27 07:18:29
【问题描述】:
我的延迟加载数据表有问题。 首先,这里是代码:
<p:tabView>
<!-- Tabs A and B, working fine -->
<p:tab title="C">
<p:commandButton value="get C" id="openC" actionListener="#{backingBean.initC}" render="cTable" update="cTable"></p:commandButton>
<p:separator/>
<p:dataTable id="cTable" var="cTable" value="#{backingBean.lazyC}" paginator="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" rows="10" sortMode="multiple" lazy="true" rendered="#{backingBean.cAvailable}">
<c:forEach var="colC" items="#{backingBean.headerAllocationC}">
<p:column headerText="#{colC.header}" sortBy="#{cTable[colC.property]}">
<div align="center">
<h:outputText value="#{cTable[colC.property]}"></h:outputText>
</div>
</p:column>
</c:forEach>
</p:dataTable>
</p:tab>
</p:tabView>
按照我的惰性数据模型的排序方法:
@Override
public List<cBean> load(int first, int pageSize, List<SortMeta> multiSortMeta, Map<String,Object> filters){
List<cBean> data = new ArrayList<cBean>();
if (multiSortMeta != null) {
for (SortMeta sortMeta : multiSortMeta) {
System.out.println("SORTFIELD:" +sortMeta.getSortField());
System.out.println("SORTORDER:" +sortMeta.getSortOrder());
//System.out.println("SORTFUNCTION:"+sortMeta.getSortFunction());
System.out.println("COLUMN:" +sortMeta.getColumn());
System.out.println("CLASS:" +sortMeta.getClass());
}
}
for (cBean c : datasource) {
boolean match = true;
if (filters != null) {
for (Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
String filterProperty = it.next();
Object filterValue = filters.get(filterProperty);
String fieldValue = String.valueOf(c.getClass().getField(filterProperty).get(c));
if (filterValue == null || fieldValue.startsWith(filterValue.toString())) {
match = true;
}
else {
match = false;
continue;
}
} catch (Exception e) {
match = false;
}
}
}
if (match) {
data.add(c);
}
}
int dataSize = data.size();
this.setRowCount(dataSize);
if (dataSize > pageSize) {
try {
return data.subList(first, first+pageSize);
} catch (IndexOutOfBoundsException e) {
return data.subList(first, first+(dataSize%pageSize));
}
} else {
return data;
}
}
我的问题: 数据表被渲染,并显示数据它应该如何做。 现在我想根据一(或多)列对表格进行排序。加载方法被调用,但传递给我的加载方法的排序字段字符串是错误的(准确地说:“属性]”被打印)。
据我了解,我的语法不应该是错误的,正如我所说,数据的显示是完全正确的。 (所以语法适用于 outputTexts,但不适用于我在 p:column 中的 sortBy 子句?!)
我的 primefaces-components 语法有问题吗? 为什么只交了财产,而不是完整的字符串? (如果移交的是 cTable[colC.property],我会以某种方式理解这种情况,但由于它只是字符串的后半部分,老实说,我完全一无所知。
如果可以为我解决问题并在最好的情况下提供解决方法,那就太好了:)
【问题讨论】:
-
到目前为止我从未使用过动态列,但我担心使用
c:forEach可能不是正确的选择,您是否尝试过使用p:columns,如showcase 所示?跨度> -
这应该有助于解释原因:stackoverflow.com/questions/29021036/…
标签: sorting jsf primefaces datatable lazy-loading