i have issues with my lazy loaded Datatable. First of all, here the code:
<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>
Following my sort-Method of my Lazy-Datamodel:
@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;
}
}
My Issue: The datatable gets rendered, and displays the data how it is supposed to do. Now I want to sort the table depending on one (or multiple) columns. The load method gets called, but the sortfield-string which is handed over to my load method is wrong (to be exact: "property]" gets printed).
As far as i understand my syntax shouldn't be wrong, as I said the display of Data is totally correct. (so the syntax works just fine with the outputTexts, but doesn't work with my sortBy-clause in p:column?!)
Is there an issue with my Syntax for primefaces-components? And why is only property] handed over, not the complete String? (i would somehow understand the situation if it was cTable[colC.property] which is handed over, but since its only the later part of the string i am utterly clueless to be honest.
Would be great if so could clear things up for me and in the best case present a workaround :)