0

更新

我有以下数据表:

<p:dataTable id="shipOwnerCompanyHistoriesTable" widgetVar="shipOwnerCompanyHistoriesTable" var="entry" value="#{shipRegisterView.ship.shipOwnerCompanyHistories}" rowKey="#{entry}" selectionMode="single" selection="#{shipRegisterView.selectedShipOwnerCompanyHistory}" 
                 styleClass="margin-bottom-10" paginator="true" rows="5"
                 paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                 rowsPerPageTemplate="5,10" emptyMessage="Δεν βρέθηκαν εγγραφές.">
                 
                <p:ajax event="rowSelect" update="@form" listener="#{shipRegisterView.selectShipOwnerCompanyHistory}" />
                <p:ajax event="rowUnselect" update="@form" listener="#{shipRegisterView.unselectShipOwnerCompanyHistory}" />

                <p:column headerText="Πλοιοκτησία">
                    <h:outputText value="#{entry.company.brandNameGreek} / #{entry.company.brandNameLatin}"/>
                </p:column>
                                    
                <p:column headerText="Από" sortBy="#{entry.fromDate}">
                    <h:outputText value="#{entry.fromDate}">
                       <f:convertDateTime pattern="dd/MM/yyyy" />
                    </h:outputText>
                </p:column>
                <p:column headerText="Έως" sortBy="#{entry.toDate}">
                    <h:outputText value="#{entry.toDate}">
                       <f:convertDateTime pattern="dd/MM/yyyy" />
                    </h:outputText>
                </p:column>
                
                <p:column headerText="Ποσοστό" sortBy="#{entry.percentage}">
                    <h:outputText value="#{entry.percentage}%"/>
                </p:column>
                
                <p:column headerText="Σημειώσεις">
                    <h:outputText value="#{entry.comments}" rendered="#{entry.comments != null and not empty entry.comments}"/>
                    <h:outputText value="-" rendered="#{entry.comments == null or empty entry.comments}"/>
                </p:column>
            </p:dataTable>

从以下视图类中获取值,如下所示:

public ShipRegisterView() {
    newFlagHistory = new ShipFlagHistory();
    lossState = "";
    growlId = "shipMessages";
    ship = new Ship();
    ship.setLossState("Normal");
    shipList = new ArrayList<Ship>();
    newEncumbrance = new ShipEncumbrance();
    newFek = new ShipFek();
    newShipEngine = new ShipEngine();
    newShipRenameHistory = new ShipRenameHistory();
    newTransferHistory = new ShipTransferHistory();
    newShipOwnerCompanyHistory = new ShipOwnerCompanyHistory();
    newShipOwnerNaturalPersonHistory = new ShipOwnerNaturalPersonHistory();
    newShipAdminCompanyHistory = new ShipAdminCompanyHistory();
    newShipUtilizationCompanyHistory = new ShipUtilizationCompanyHistory();
    newShipOwnerCompanyHistory.setCompany(new Company());
    newShipOwnerNaturalPersonHistory.setNaturalPerson(new NaturalPerson());
    newShipAdminCompanyHistory.setCompany(new Company());
    newShipUtilizationCompanyHistory.setCompany(new Company());
    newConditionHistory = new ShipConditionHistory();
    newRecreationalLicense = new RecreationalLicense();
    newRecreationalLicense.setAdminClassAct(new AdminClassAct());
    newRecreationalLicense.setAdminDeclassAct(new AdminDeclassAct());
    searchInspectionsList = new ArrayList<Inspection>();
    searchCertificatesList = new ArrayList<Certificate>();
    searchRosCertificatesList = new ArrayList<Certificate>();
    searchAffirmationsList = new ArrayList<Affirmation>();
    
    newNaturalPerson = new NaturalPerson();
    newNaturalPerson.setAddress(new Address());
    searchNaturalPerson = new NaturalPerson();
    
    harboursForShipsForDNPUser = new ArrayList<Harbour>();

    fines = new ArrayList<Fine>();
    complaints = new ArrayList<Complaint>();
    completedRoutes = new ArrayList<CompletedRoute>();

    searchOwnerCompany = new SearchCompany();
    searchOwnerNaturalPerson = new SearchNaturalPerson();
    searchAdminCompany = new SearchCompany();
    searchUtilizationCompany = new SearchCompany();

    ship.setShipEngines(new HashSet<ShipEngine>());
    ship.setShipAdminCompanyHistories(new HashSet<ShipAdminCompanyHistory>());
    ship.setShipOwnerCompanyHistories(new HashSet<ShipOwnerCompanyHistory>());
    ship.setShipOwnerNaturalPersonHistories(new HashSet<ShipOwnerNaturalPersonHistory>());
    ship.setShipUtilizationCompanyHistories(new HashSet<ShipUtilizationCompanyHistory>());
    ship.setShipEncumbrances(new HashSet<ShipEncumbrance>());
    ship.setShipConditionHistories(new ArrayList<ShipConditionHistory>());
    ship.setShipFeks(new HashSet<ShipFek>());
    ship.setDocuments(new HashSet<AccompanyingFile>());
    ship.setShipPhotos(new HashSet<ShipPhoto>());
    ship.setShipFlagHistories(new HashSet<ShipFlagHistory>());
    ship.setRecreationalLicenses(new HashSet<RecreationalLicense>());
    ship.setShipTransferHistories(new HashSet<ShipTransferHistory>());
    ship.setLossTheftDecisions(new HashSet<LossTheftDecision>());
    ship.setShipRenameHistories(new HashSet<ShipRenameHistory>());
    
    List<ShipOwnerCompanyHistory> list = new ArrayList<>(shipOwnerCompanyHistories);
    
};

 

我想做的事情是使用sortByprimefaces 的属性对表的列进行排序。当我按列时,我在网页上收到以下错误: 在此处输入图像描述

在我的tomcat上:

错误 (com.liferay.faces.bridge.context.internal.ExceptionHandlerAjaxImpl.java:71).handle - 数据类型应该是 java.util.List 或 javax.faces.model.ListDataModel 实例才能排序。

现在,我知道它必须是一个列表才能工作,但是有没有办法可以对表格进行排序?Hibernate 映射也是一个set

<set name="shipOwnerCompanyHistories" inverse="true" cascade="all-delete-orphan" lazy="false" >
        <key column="shipId" on-delete="cascade"/>
        <one-to-many class="gr.yptp.hcg.sr.Model.ShipOwnerCompanyHistory"/>
    </set>

让我知道。我真的很感谢你的帮助。

4

1 回答 1

0

代替

ship.setShipOwnerCompanyHistories(new HashSet<ShipOwnerCompanyHistory>());

并进一步

List<ShipOwnerCompanyHistory> list = new ArrayList<>(shipOwnerCompanyHistories);

(列表变量不再使用,在你的IDE中它下面不是有一个黄色的松鼠林吗?)

 ship.setShipOwnerCompanyHistories(new ArrayList<>(new HashSet<ShipOwnerCompanyHistory>()));

要不就

 ship.setShipOwnerCompanyHistories(new ArrayList<ShipOwnerCompanyHistory>());

或者您检索了shipOwnerCompanyHistories变量(假设它是数据库中的 HashSet,请执行

 ship.setShipOwnerCompanyHistories(new ArrayList<>(shipOwnerCompanyHistories));
于 2020-07-14T15:50:57.287 回答