开发者

JSF 2.0 Sortable headers with h:datatable

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;
}


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜