I'm trying to add sortable headers to an h:dataTable. I'm attempting to follow http://balusc.blogspot.com/2006/06/using-datatables.html to do this. The following renders a link but it doesn't do anything.
list.xhtml
<h:dataTable value="#{iptableController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
<h:column>
<f:facet name="header">
<h:commandLink actionListener="#{iptableController.sortDataList}">
<f:attribute name="sortField" value="getID"/>
<h:outputText value="#{bundle.ListIptableTitle_iptableId}"/>
</h:commandLink>
</f:facet>
<h:outputText value="#{item.iptableId}"/>
</h:column>
Here is the a portion of the controller I'm trying to use.
iptableController
public void sortDataList(ActionEvent event) {
String sortFieldAttribute = getAttribute(event, "sortField");
// Get and set sort field and sort order.
if (sortField != null && sortField.equals(sortFieldAttribute)) {
sortAscending = !sortAscending;
} else {
sortField = sortFieldAttribute;
sortAscending = true;
}
// Sort results.
if (sortField != null) {
Collections.sort(getFacade().findAll(), new DTOComparator(sortField, sortAscending));
}
}
The DTOCompartor is identical to the one in the link.
I feel like I've gone down the wrong path completely, but have been unable to find a better guide. Any help at all would be appreciated.
EDIT:
I turned on finer filtering and was able to see a problem. I'm not sure what was causing it, but it looks like the controller was being added twice and was allocated to the <error>.
package. I renamed the file and that was resolved. After cleaning up a few other issues (calling non-existant functions etc) I'm stuck with the error:
SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt12:j_idt22, Message=/iptable/List.xhtml @26,88 actionListener="#{Controller.sortList}": java.lang.RuntimeException: Cannot compare test, test with t, test1 on [getiptableID]
SEVERE: /iptable/List.xhtml @26,88 actionListener="#{Controller.sortList}": java.lang.RuntimeException: Cannot compare test, test with t, test1 on [getiptableID]
the comment in DTOComparator indicates that: // If this exception occurs, then it is usually a fault of the DTO developer.
my getters all look like:
public String getIptableName() {
return iptableName;
}