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:
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.
new ArrayList<>(yourHashSet)
? – Jasper de Vriesnew 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 KrousList<ShipOwnerCompanyHistory> list = new ArrayList<>(shipOwnerCompanyHistories);
– Jasper de VriesShipRegisterView
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