简体   繁体   English

排序h:dataTable

[英]Sorting h:dataTable

I am using Seam and Java to make an h:dataTable that contains information from a ArrayList filled with objects. 我正在使用Seam和Java制作h:dataTable,其中包含来自填充有对象的ArrayList的信息。 My question is, is there any way to sort the table by clicking on one of the headers. 我的问题是,是否可以通过单击标题之一来对表进行排序。 I have some code right now and all it does is reload the table the same way that it was. 我现在有一些代码,它所做的就是以与以前相同的方式重新加载表。

Here's some of my code. 这是我的一些代码。 Let me know if you need more: Table: 让我知道是否需要更多:表:

<h:dataTable value="#{deliveryPort.getWholeDeliveryList()}" var="delivery" rules="rows">
                    <h:column>
                        <div class="setWidth">
                            <div class="white">
                            <f:facet name="header">
                                <h:outputLink style="color:#FFFFFF" action="#{deliveryPort.sortByAddress()}">
                                    Address
                                </h:outputLink>
                            </f:facet>
                            </div>
                            <h:outputText value="#{delivery.address}" />
                        </div>
                    </h:column>

Sort: 分类:

    public String sortByAddress(){
    for(int i = 0; i < wholeDeliveryList.size(); i++){
        for(int j= i+1; j<wholeDeliveryList.size(); j++){
            if(wholeDeliveryList.get(i).getAddress().compareTo(wholeDeliveryList.get(j).getAddress())<1){
                FlowerStoreDelivery temp = wholeDeliveryList.get(i);
                wholeDeliveryList.set(i, wholeDeliveryList.get(j));
                wholeDeliveryList.set(j, temp);
            }
        }
    }
    return "deliveryList.seam";
}

getWholeDeliveryList(): getWholeDeliveryList():

    public List<FlowerStoreDelivery> getWholeDeliveryList(){
wholeDeliveryList = new ArrayList<FlowerStoreDelivery>();
wholeDeliveryList.addAll(entityManager.createQuery("SELECT e FROM FlowerStoreDelivery e").getResultList());
    return wholeDeliveryList;
}

您可以从JSF专家BalusC的 博客上获得有关DataTable的更多信息,包括排序以及更多信息。

例如,Richfaces的rich:dataTable支持通过单击列进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM