0
votes

UPDATED

I have the following dataTable:

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

With the value being taken from the follwoing view class like so:

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

 

The thing i am trying to do is to sort the columns of the table using the sortBy attribute of primefaces. When i press the column, i get the following error on the webpage: enter image description here

And on my tomcat:

ERROR (com.liferay.faces.bridge.context.internal.ExceptionHandlerAjaxImpl.java:71).handle - Data type should be java.util.List or javax.faces.model.ListDataModel instance to be sortable.

Now, i understand that it has to be a list in order to work, but is there a way where i can sort the table? Hibernate mapping is a set too:

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

Let me know. I really appreciate your help.

1
How about new ArrayList<>(yourHashSet)?Jasper de Vries
Like that? new ArrayList<>(HashSet<ShipOwnerCompanyHistory>()); I'm getting an error: Syntax error on token "(", Expression expected after this token. It refers to the parenthesis after <ShipOwnerCompanyHistory>Nikos Krous
No. List<ShipOwnerCompanyHistory> list = new ArrayList<>(shipOwnerCompanyHistories);Jasper de Vries
So, I am writing this line under the one I posted in my view class, inside the ShipRegisterView method, but it doesn't seem to work, as it produces an error. Sorry for that, I am new to jsf and honestly sometimes I'm at a loss.Nikos Krous
'an error' ???? Hard to help with that and please edit the question with an update and add the real code there that you changed. Then we can see what you actually haveKukeltje

1 Answers

0
votes

Instead of

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

and further on

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

(where the list variable is nowhere used anymore, doesn't it have a yellow squirreled lin under it in your IDE?)

Do

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

or just

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

or you you retrieved the shipOwnerCompanyHistories variable (assuming it is a HashSet from the database, do

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