0

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.

  • How about `new ArrayList<>(yourHashSet)`? – Jasper de Vries Jul 14 '20 at 12:29
  • Like that? `new ArrayList<>(HashSet());` I'm getting an error: Syntax error on token "(", Expression expected after this token. It refers to the parenthesis after `` – Nikos Krous Jul 14 '20 at 12:39
  • No. `List list = new ArrayList<>(shipOwnerCompanyHistories);` – Jasper de Vries Jul 14 '20 at 12:44
  • 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 Jul 14 '20 at 13:05
  • '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 have – Kukeltje Jul 14 '20 at 13:57
  • @Kukeltje Edited the question. – Nikos Krous Jul 14 '20 at 14:41
  • So you have the same error? The java code you have after the edit is very weird. Are you new to java too? – Kukeltje Jul 14 '20 at 15:08
  • Error is the same yes, it can't find `shipOwnerCompanyHistories` which I get, it's just that I can't seem to understand what I should put inside the parenthesis in `new ArrayList<>()`. The code was already written... Right now I'm resolving bugs and implementing new functionality where it is needed. I am a beginner developer also. – Nikos Krous Jul 14 '20 at 15:16
  • @Kukeltje Added the whole method of the my view class, maybe it will help. – Nikos Krous Jul 14 '20 at 15:20
  • 1: It is not about whole methods... 2: To me seems you are indeed relatively new (web)development (not a problem, just notice this due to the code weird assignment to variables and not using them... hmmm). 3: Did not not occur to you that you have a problem with the `shipOwnerCompanyHistories` field and the suggested code change is nowhere assigned to this field? so do `ship.setShipOwnerCompanyHistories(new ArrayList(new HashSet()));` – Kukeltje Jul 14 '20 at 15:43

1 Answers1

0

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));
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • I'll do whatever I can to fix it... Thank you very much for your time and your help. I know I have a lot to learn. If I get it to work, I'll mark the answer. – Nikos Krous Jul 14 '20 at 16:27