tags:

views:

30

answers:

1

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;
}
+1  A: 

The following renders a link but it doesn't do anything.

A common cause is that it's not been placed inside a <h:form>. Without it, the client can't submit anything to the server. Place the <h:dataTable> inside a <h:form> and it should work.

If that's not the cause, then check this answer for a list of other possible causes.


Update as per your update:

Cannot compare test, test with t, test1 on [getiptableID]

This means that there is no getter with the name getiptableID. Shouldn't it be getIptableID?

BalusC
Thanks for your quick response. The list.xhtml has a form defined: <h:form styleClass="jsfcrud_list_form">.I've checked 1-3 in the link you've provided and I'm pretty sure those aren't occurring. I don't quite know how to check 4-7.Here is the full file: http://pastebin.com/S4hpS1Ggand the full controller: http://pastebin.com/Kz6T3UZEfull entity: http://pastebin.com/6tN93Dui
duallain
Then it should have done *something*. Is the server ever hit? Which phases of JSF lifecycle are been processed?
BalusC
I've added more information above. It was hitting the server, just wasn't doing anything visible to me.
duallain