Basically, I have 2 collections of objects: List and List. Each person has a value in each criteria, which builds the matrix to be displayed:
criteria1 criteria2 criteria3 ...
person1 2 5 8
person2 4 3 1
person3 6 9 0
...
The number of elements in each collection is unknown since they are coming from query results. My model has 3 tables: criteria, person and criteria_person (which has the personId, criteriaId and qualification).
I have been able to display the datatable with these collections but I have no clue about how to relate them to the qualification associated to them, and then make them persist. So, any guidance would be much appreciated.
You just asked such a wide question. For this you can use row expansion see more
You can simple add a table with person name and criteria would be it's inner table like in the example on the showcase.
here is sample example:
<p:dataTable var="person" value="#{dtBasicView.peronsViewList}">
<f:facet name="header">
Person with criteria
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Person Name">
<h:outputText value="#{person.personName}" />
</p:column>
<p:column headerText="Reg. Date">
<h:outputText value="#{person.regDate}" />
</p:column>
<p:rowExpansion>
<p:panelGrid columns="2" columnClasses="label,value" style="width:300px">
<p:dataTable var="cri" value="#{person.criteria}">
<p:column headerText="Id">
<h:outputText value="#{cri.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{cri.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{cri.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{cri.color}" />
</p:column>
</p:dataTable>
</p:panelGrid>
</p:rowExpansion>
</p:dataTable>
I am not sure if I understood the question 100%, but I solved something similar with p:columns and a backing bean method which resolves the value for the current cell:
<p:dataTable value="#{curSearch.getSearchResults()}" var="curSearchResult">
<p:columns value="#{curSearch.determineItems()}" var="curSearchItem">
<f:facet name="header">
<h:outputText value="#{curSearchItem}" />
</f:facet>
<h:outputText value="#{someUiBusinessLogicBean.generatePropertyValue(curSearchResult, curSearchItem)}" />
</p:columns>
</p:dataTable>
Hope this shows the idea. But I would recommend to build a handy UI model.
Related
I have this problem, and I don't understand why...I used it all the time in this way
<p:dataTable id="datatable" var="ligne" value="#{ficheMB.lignes}"
selection="#{ficheMB.selectedLignes}" rowKey="#{ligne.id}" >
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Article">
<h:outputText value="#{ligne.article.nom}" />
</p:column>
<p:column headerText="Tarif">
<h:outputText value="#{ligne.article.tarif}" />
</p:column>
this is the error
javax.faces.FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.
at org.primefaces.component.datatable.DataTable.getRowKeyFromModel(DataTable.java:1409)
at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:1244)
at org.primefaces.component.datatable.DataTableRenderer.encodeRows(DataTableRenderer.java:1184)
thank you for your help
After filtering of primefaces 'tasksDataTable', the 'number of records' does not update.
For example before filtering number of records is 45, and by filtering table i get 3 records as result. But 'number of records' is already 45 (i expect to show 3 for 'number of records' after filtering).
How can i handle it?
<p:dataTable var="recordEntity"
id="rulesDataTable"
widgetVar="rulesDataTable"
value="#{bossCartable.tasksDataTable}"
paginator="true"
paginatorAlwaysVisible="false"
rows="#{paginationModel.rows}"
paginatorTemplate="#{paginationModel.paginationTemplate}"
rowsPerPageTemplate="#{paginationModel.rowsPerPageTemplate}"
currentPageReportTemplate="#{paginationModel.currentPageReportTemplate}"
selectionMode="single"
selection="#{bossCartable.selectedRuleRow}"
rowIndexVar="rowIndex"
sortBy="#{recordEntity.id}"
emptyMessage="No record found!"
rowKey="#{recordEntity.id}"
resizableColumns="true"
>
<f:facet name="header">
<div class="row align-content-center">
Tasks
<h:outputLabel value="number of records: #{bossCartable.tasksDataTable.size()}"/>
</div>
</f:facet>
<p:column headerText="id" width="5%" filterMatchMode="contains"
filterBy="#{recordEntity.id}" sortBy="#{recordEntity.id}" sortable="true">
<h:outputText value="#{recordEntity.id}"/>
</p:column>
<p:column headerText="description" filterMatchMode="contains"
filterBy="#{recordEntity.description}">
<h:outputText value="#{recordEntity.description}"/>
</p:column>
<p:column headerText="startDate" width="8%" filterMatchMode="contains"
filterBy="#{recordEntity.startDate}">
<h:outputText value="#{recordEntity.startDate}"/>
</p:column>
<p:column headerText="endDate" width="8%" filterMatchMode="contains"
filterBy="#{recordEntity.endDate}">
<h:outputText value="#{recordEntity.endDate}"/>
</p:column>
</p:dataTable>
With non lazy loading the filtered value can be stored using the filteredValue attribute. See: https://primefaces.github.io/primefaces/8_0/#/components/datatable
This will allow you to use:
<p:dataTable value="#{bossCartable.tasksDataTable}"
filteredValue="#{bossCartable.tasksFiltered}"
...>
</p:dataTable>
and
#{bossCartable.tasksFiltered.size()}
where tasksFiltered should point to a writable List.
Also, your header facet will not be updated by magic, you should put you text in a component and update that component on the filter event of the data table.
See also:
Primefaces datatable update in f:facet name="header" not working
https://primefaces.github.io/primefaces/8_0/#/components/datatable?id=ajax-behavior-events
I have a treeTable where I have to set on the first column a Radionbutton.
the RadionButton is not linked to the treeTable.
I tried with the selectionMode but in vain.
If you have any idea, please share it with me.
Thanks in advance :)
My treeTable should look like this :
here is the code I used :
<p:treeTable value="#{treeBouchon.racine}" var="ligneBudgetaire"
selection="#{treeBouchon.ligneBudgetaireselectionnee}"
selectionMode="single" rowKey="#{ligneBudgetaire.id}">
<p:column selectionMode="single">
</p:column>
<p:column headerText="Ligne budgétaire">
<h:outputText value="#{ligneBudgetaire.filed1}" />
</p:column>
<p:column headerText="ETP reçus">
<h:outputText value="#{ligneBudgetaire.filed2}" />
</p:column>
<p:column headerText="ETP émis">
<h:outputText value="#{ligneBudgetaire.filed3}" />
</p:column
</p:treeTable>
I am using PrimeFaces 3.2 and want to export a dynamically created table as an .xls file. When i click on export, nothing seems to be happening.
Export Code
<h:commandLink id="Download_Excel_Format" ajax="false">
<p:graphicImage value="/resources/Excel_Icon.jpg" height="25" width="25" />
<p:dataExporter type="xls" target="dataTable" fileName="SomeFileName"/>
</h:commandLink>
dataTable
<p:dataTable id="dataTable" var="c" value="#{databaseSearch.customerList}"
paginator="true" rows="10" paginatorAlwaysVisible="false"
paginatorTemplate="Page {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} Rows per page {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,30">
<p:column>
<f:facet name="header">
<h:outputText value="Machine" />
</f:facet>
<p:commandButton id="basic" value="#{c.machine}" action="#{updateEntry.setMachine(c.machine)}" oncomplete="dlg1.show();" styleClass="ui-Machinebutton" update=":Update_Entry"/>
<p:tooltip for="basic" value="Update/Delete Database Entry" showEffect="fade" hideEffect="fade" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Company" />
</f:facet>
<h:outputText value="#{c.company}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Contact" />
</f:facet>
<h:outputText value="#{c.contact}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Phone" />
</f:facet>
<h:outputText value="#{c.phone}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Email" />
</f:facet>
<!-- <h:outputText value="#{c.email}" />-->
<h:outputLink value="mailto:#{c.email}?Subject=Baseline Monitor Alert | Machine : #{c.machine}">#{c.email}</h:outputLink>
</p:column>
</p:dataTable>
Both the dataTable and the Export command are within one form, however the dataTable is in a output panel (within the form).
Form
<h:form prependId="false" id="Main_Form">
</h:form>
Output Panel
<p:outputPanel id="panel" autoUpdate="false">
</p:outputPanel>
I even updated to PrimeFaces 3.4.2 to see if the dataExporter would work, but no avail, as far as i remember 3.2 has a bug if the dataTable generates columns dynamically, but that is not the case here right? am i doing something wrong?
dataExporter option looks much simpler, but if there is an alternative which is simple enough i am up for it.
Update
I am using a GlassFish 3.1.2.2 (build 5) & NetBeans 7.2.1, i do not get any errors, just the page refresh's, has a '#' at the end of the URL and stops, no errors means that i am not lacking any dependencies either... so i am lost here ...
Ok, i found the answer ! Tricky one though ... i had a commandButton with the ID=submit...renamed it and that did the trick !
<p:commandButton id="xsubmit" icon="ui-icon-search" title="Search Database" update="panel" actionListener="#{databaseSearch.customerList}" />
can we do a internal sorting in primeface datetable ? If i have column a ,b ,c. can i sort the column c and then internally by column b in p:dataTable.
<h:form>
<p:dataTable var="car" value="#{tableBean.carsSmall}">
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="a">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="b">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="c">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
</h:form>
Yes, you can. http://www.primefaces.org/showcase/ui/datatableSortingMultiple.jsf
P.S Don't forget pressing CTRL or Cmd :)