I have a simple Primefaces Datatable with a SummaryRow. The values of this SummaryRow are calculated in the ManagedBean and available in simple BigDecimal variables. The DataTable is ordered by a String field.
Somehow, the DataTable is being displayed with the summaryRow in every row, and not in the last row.
I've searched for this but didn't find anything about.
I'm using Primefaces 5.3 with JSF 2.2.
The table:
(https://drive.google.com/file/d/0Bw9aJmydXWmvdU8yTUkyYnp0Ums/view)
The XHTML:
<p:dataTable
id="rgmStoricoContrattiSogettoCapogruppoDataTable"
value="#{storicoSoggettoProdottoBean.sogegettoProdottoList}"
var="soggetto"
rendered="#{storicoSoggettoProdottoBean.isNdgMemberOfGroup()}"
styleClass="common_datagrid"
emptyMessage="Nessun valore presente"
sortBy="#{soggetto.denominazione}" >
<p:column headerText="Soggetto">
<p:commandLink
value="#{soggetto.denominazione} #{soggetto.ndg} - #{soggetto.ndgCapogruppo}"
actionListener="#{storicoSoggettoProdottoBean.redirectSoggetoProdotto(request.contextPath, soggetto)}"
immediate="true"
process="#this"
style="font-size: 11px !important;" />
</p:column>
<p:column headerText="Rating And./Cerved" width="67" style="text-align: center">
<h:outputText value="#{soggetto.rating} / #{soggetto.ratingCerved}" />
</p:column>
<p:column headerText="Perfez. storico" width="60" style="text-align: right">
<h:outputText value="#{soggetto.perfezionato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Accord." width="60" style="text-align: right">
<h:outputText value="#{soggetto.accordato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Utilizz." width="60" style="text-align: right">
<h:outputText value="#{soggetto.utilizzato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Sconfino" width="60" style="text-align: right">
<h:outputText value="#{soggetto.sconfino}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="In proposta" width="60" style="text-align: right">
<h:outputText value="#{soggetto.inProposta}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Garanzie bancarie" width="60" style="text-align: right">
<h:outputText value="#{soggetto.garanzieBancarie}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Rischio indiretto vs gruppo" width="87" style="text-align: center;">
<h:outputText rendered="#{soggetto.rischioIndirettoVsGruppo == true}" value="SÍ" style="color: green; font-weight: bold;" />
</p:column>
<p:column headerText="Rischio indiretto vs terzi" width="60" style="text-align: right">
<h:outputText value="#{soggetto.rischioIndirettoVsTerzi}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Rischio pond." width="60" style="text-align: right">
<h:outputText value="#{soggetto.rischioPonderato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column width="25">
<p:commandButton
action="#{storicoSoggettoProdottoBean.redirectToStoricoPlafond(request.contextPath, soggetto)}"
immediate="true"
process="#this"
icon="fa fa-file-text-o"
styleClass="imageButton"
style="height: 12px;" />
</p:column>
<p:summaryRow>
<p:column styleClass="totaleRowColor" style="text-align: right;">
<h:outputText value="Totale:" style="font-weight: bold; text-transform: uppercase;" />
</p:column>
<p:column styleClass="totaleRowColor" width="67" />
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.perfezionatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.accordatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.utilizzatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.sconfinoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.inPropostaSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.garanzieBancarieSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" width="87" />
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.rischioIndirettoVsTerziSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.rischioPonderatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" width="25" />
</p:summaryRow>
As noted in this question, you have to provide the sortBy attribute on the p:dataTable tag for the summary row to work (as you did in your code snippet). Primefaces uses the expression in the sortBy tag to group the table entries and then provide a summary row for each group.
To get only one group, I tried this:
<p:dataTable sortBy="#{1}" ...>
Works fine for me, I get just one summary row with my grand total now.
Not sure if colspan attribute on column is required for expected result...?
Check the showcase of Primefaces for a sample if you didn't know: http://www.primefaces.org/showcase/ui/data/datatable/summaryRow.xhtml
The summary row uses the sortBy expression, So if you use a sortBy that is say a unique ID, then Primefaces is always going to provide a summary row for every row in the table. Using a constant for sortBy like Ginkobonsai suggests sortBy="#{1}" is a good idea, You could alternatively use a constant field in the POJO.
You can use a sortby value of some data that is shared by all of the rows.
Eg if you are using var soggetto
then you can have a field on that class that is equal across all objects.
Eg soggetto.dummysortby
in the class getDummySortBy returns 1.
Related
I've tried with primefaces showcase examples, but I don't know how to make a grouping datatable with checkbox selection like this:
I've tried with subtable, p:column and p:row, but still I don't have an idea how to get same results such as if I use panelGrid.
If you want to check multiple rows with one checkbox in the 'grouped' column, that is not supported in PrimeFaces up to the 6.3-SNAPSHOT. If it is/will be supported in future releases depends on an issue being created and it getting enough support or sponsor this via paid consultancy.
Row grouping is what comes closest
<h3>Rowspan</h3>
<h:form>
<p:dataTable var="car" value="#{dtRowGroupView.cars}" sortBy="#{car.brand}">
<p:column headerText="Brand" groupRow="true">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
</h:form>
But I've not seen this work with selection or an additional 2nd grouped row
The idea of this table was to compare the different values of each field to decide if the assumed id and name are taken as good. Here is an example:
I used ui:repeat, p:row and p:column to get this customized table:
<h:form id="stocktakingTable">
<h:panelGroup layout="block" class="col-lg-10 col-md-10 col-lg-offset-1">
<p:panelGrid>
<f:facet name="header">
<p:row>
<p:column>Ok</p:column>
<p:column>Assumed id</p:column>
<p:column>Assumed name</p:column>
<p:column>Place</p:column>
<p:column>Id</p:column>
<p:column>Name</p:column>
<p:column>Main color</p:column>
<p:column>Size</p:column>
</p:row>
</f:facet>
<ui:repeat value="#{oneCtrl.stocktakingList}" var="stocktaking">
<p:row>
<p:column rowspan="4">
<p:selectBooleanCheckbox value="#{stocktaking.ok}" disabled="#{stocktaking.ok}" valueChangeListener="#{oneCtrl.updateStocktaking(stocktaking)}">
<p:ajax update=":#{p:component('stocktakingTable')}"/>
</p:selectBooleanCheckbox>
</p:column>
<p:column rowspan="4" style="font-weight: #{stocktaking.ok ? 'normal' : 'bold'}">#{stocktaking.assumedId}</p:column>
<p:column rowspan="4" style="font-weight: #{stocktaking.ok ? 'normal' : 'bold'}">#{stocktaking.assumedName}</p:column>
<p:column style="font-style: italic">Real Stocktaking</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realId)}">#{stocktaking.realId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realName)}">#{stocktaking.realName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realColor)}">#{stocktaking.realColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realSize)}">#{stocktaking.realSize}</p:column>
</p:row>
<p:row>
<p:column style="font-style: italic">Calculated stocktaking</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedId)}">#{stocktaking.calculatedId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedName)}">#{stocktaking.calculatedName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedColor)}">#{stocktaking.calculatedColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedSize)}">#{baseCtrl.calculatedSize}</p:column>
</p:row>
<p:row>
<p:column style="font-style: italic">Shop web page</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopId)}">#{stocktaking.shopId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopName)}">#{stocktaking.shopName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopColor)}">#{stocktaking.shopColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopSize)}">#{stocktaking.shopSize}</p:column>
</p:row>
<p:row>
<p:column style="font-style: italic">Online shop web page</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineId)}">#{stocktaking.onlineId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineName)}">#{stocktaking.onlineName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineColor)}">#{stocktaking.onlineColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineSize)}">#{stocktaking.onlineSize}</p:column>
</p:row>
<p:row>
<p:column colspan="8" styleClass="ui-widget-header"/>
</p:row>
</ui:repeat>
</p:panelGrid>
</h:panelGroup>
</h:form>
I’m sorry if I wasn’t clear enough at first :'(
I have class Task and class File which have List<Task> tasks as attribute.
How can I display details of tasks in datatable which contains details of file?
<p:dataTable var="files" value="#{fileMB.files}" id="file" >
<p:column style="width:35px">
<p:rowToggler />
</p:column>
<p:column headerText="FileName" style="text-align: center;"
sortBy="#{files.fileName}" filterBy="#{files.fileName}">
<h:outputText value="#{files.fileName}" />
</p:column>
<p:column headerText="TaskName" style="text-align: center;">
<h:outputText value="#{file.tasks.taskName}" />
</p:column>
</p:dataTable>
An Error Occurred:For input string: "taskName"
pb resolved : I use "get":
<p:column headerText="TaskName" style="text-align: center;">
<h:outputText value="${files.tasks.get(0).taskName}"/>
</p:column>
My problems is that when I click in the button to export data table, It exports only columns headers, my excel file is generated with none rows.
<h:form>
<p:dataTable id="cteTable" var="cte"
emptyMessage="Nenhum Registro Localizado"
reflow="true" value="#{extratorBean.ctes}" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
style="margin-top: 10px" paginator="true" rows="100" scrollable="true" scrollWidth="1024px">
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage name="images/excel.png" width="24" library="samsung" />
<p:dataExporter type="xls" target="cteTable" fileName="cte-s" />
</h:commandLink>
</f:facet>
<p:column headerText="CNPJ Emissor" width="150" style="text-align: center">
<h:outputText value="#{cte.EMIT_CNPJ}"/>
</p:column>
<p:column headerText="Serie" width="60" style="text-align: center">
<h:outputText value="#{cte.IDE_SERIE}"/>
</p:column>
<p:column headerText="N° CT-e" width="90" style="text-align: center">
<h:outputText value="#{cte.IDE_NCT}"/>
</p:column>
<p:column headerText="Dt. Emissão" width="150" style="text-align: center">
<h:outputText value="#{cte.IDE_DHEMI}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Total Frete" width="80" style="text-align: center">
<h:outputText value="#{cte.VPREST_VTPREST}">
<f:convertNumber type="currency" />
</h:outputText>
</p:column>
<p:column headerText="ICMS" width="80" style="text-align: center">
<h:outputText value="#{cte.ICMS_VICMS}">
<f:convertNumber type="currency" />
</h:outputText>
</p:column>
<p:column headerText="% ICMS" width="80" style="text-align: center">
<h:outputText value="#{cte.ICMS_PICMS}">
<f:convertNumber minFractionDigits="2" />
</h:outputText>
</p:column>
<p:column headerText="Nat. Op." width="350" style="text-align: center">
<h:outputText value="#{cte.IDE_NATOP}"/>
</p:column>
<p:column headerText="CNPJ Tomador" width="150" style="text-align: center">
<h:outputText value="#{cte.TOMADOR}"/>
</p:column>
<p:column headerText="Chave Acesso" width="350" style="text-align: center">
<h:outputText value="#{cte.TRANSACTIONID}"/>
</p:column>
<p:column headerText="Dt. Criação" width="120" style="text-align: center">
<h:outputText value="#{cte.IDE_TIMESTAMP}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="N° Protocolo" width="120" style="text-align: center">
<h:outputText value="#{cte.IDE_AUTHCODESEFAZ}"/>
</p:column>
</p:dataTable>
</h:form>
I'm using primefaces 5.3 and tried to use apache poi 3.8 and 3.10-FINAL but both did not work right.
In the log i've got no errors.
Edit: I already know what is happening.
The problem is that when my table is load, it's empty, but looks like the button to export It to excel, keeps some kind of cache with the table empty, and even after I load data into the table, the button keeps exporting the excel empty.
Now, I don't know how to solve this problem.
Well, if someone else get into this problem, here is the answer that corrects mine:
My managed bean was request scoped. But when I clicked the button to export excel, It makes a new request to the maneged bean. And in this request my list was null. I checked this by putting a breakpoint in the method getList.
So I simply change the scope of my managed bean from request scope to view scope and It works fine.
It seems that the exporter use the property for filtered data, so at the first time, you get only headers because the filtered data is empty. I suggest try adding data to the filtered data in the load of the page.
add f:facet header after your p:column
<p:column>
<f:facet name="header">
<h:outputText value="CNPJ Emissor"/>
</f:facet>
<h:outputText value="#{cte.EMIT_CNPJ}"/>
</p:column>
I read many answers abot this issue, they say I should add an item to the list that feed the datatable and then refresh the form, but this does not work in my progect. this is my datatable:
<p:dataTable var="rowItem"
scrollable="true"
scrollHeight="100%"
id="flussiGuestSummary"
emptyMessage="nessun flusso guest selezionato"
value="#{fileMatchMB.selectedGuests}"
rowKey="#{rowItem.row}">
style="width:10px;text-align:center" />
<p:column headerText="Date Valuta"
width="30">
<h:outputText value="#{rowItem.data}">
<f:converter
converterId="filematch.interfaccia.CalendarConverter" />
</h:outputText>
</p:column>
<p:column headerText="Importo"
style="text-align: center; width:30px;">
<h:outputText value="#{rowItem.amount}">
<o:converter converterId="javax.faces.Number"
currencySymbol="#{rowItem.getCurrencySymbol()}"
type="currency" />
</h:outputText>
</p:column>
<p:column headerText="Descrizione"
styleClass="scrollableCell"
style="text-align: center; width:80px;">
<h:outputText value=" #{rowItem.descrizione}">
<f:converter converterId="filematch.interfaccia.StringShortner" />
<f:attribute name="shortnerActive"
value="#{fileMatchMB.shortnerActive}" />
</h:outputText>
</p:column>
<p:column headerText="Causale"
styleClass="scrollableCell"
style="text-align: center; width:30px;">
<h:outputText value=" #{rowItem.causale}"
width="100">
<f:converter converterId="filematch.interfaccia.StringShortner" />
<f:attribute name="shortnerActive"
value="#{fileMatchMB.shortnerActive}" />
</h:outputText>
</p:column>
<p:column headerText="match"
styleClass="scrollableCell"
style="text-align: center; width:10px;">
<h:outputText value=" #{rowItem.match}">
<f:converter converterId="filematch.interfaccia.StringShortner" />
<f:attribute name="shortnerActive"
value="#{fileMatchMB.shortnerActive}" />
</h:outputText>
</p:column>
<f:facet name="footer">
"#{fileMatchMB.countGuest} / #{fileMatchMB.guestList.size()} #{msg.msg_records}"
</f:facet>
</p:dataTable>
the code in the backing bean:
this.selectedGuests = selected_list;
I am sure selected_list is nort empty, but my datatable remains empty, what am I doing wrong?
I'm trying to get value from 7 classes, for 7 columns
for interval one, interval two and so on for each student I have >
but the data table get's empty, but Java code is working fine.
I think the problem in html code tags
here is:
</h:form>
<h:form id="hesham1">
<p:scrollPanel style="width:100%;height:100%">
<p:dataTable var="car" value="#{tableBean.carsSmall}" id="hesham" encoding="windows-1256" dir="rtl" emptyMessage="لا يوجد بيانات او تأكد من البيانات المستعلم عنها">
<f:facet name="header">
الاستعلام عن صف 2-10
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="اسم الطالب"/>
<p:column rowspan="2" headerText="التاريخ" />
<p:column colspan="3" headerText="الحصة الاولى" style="text-align: center;"/>
<p:column colspan="3" headerText="الحصة الثانية" style="text-align: center;"/>
<p:column colspan="3" headerText="الحصة الثالثة" style="text-align: center;"/>
<p:column colspan="3" headerText="الحصة الرابعة" style="text-align: center;"/>
<p:column colspan="3" headerText="الحصة الخامسة" style="text-align: center;"/>
<p:column colspan="3" headerText="الحصة السادسة" style="text-align: center;"/>
<p:column colspan="3" headerText="الحصة السابعة" style="text-align: center;"/>
</p:row>
<p:row>
<p:column headerText="المعلم" >
<h:outputText value="#{car.teachers}" />
</p:column>
<p:column headerText="الماده" >
</p:column>
<p:column headerText="الحالة" >
<h:outputText value="#{car.state}" />
</p:column>
<p:column headerText="المعلم" >
<h:outputText value="#{interval2.teachers2}" />
</p:column>
<p:column headerText="الماده" />
<p:column headerText="الحالة" >
<h:outputText value="#{interval2.state2}" />
</p:column>
<p:column headerText="المعلم" >
<h:outputText value="#{interval3.teachers3}" />
</p:column>
<p:column headerText="الماده" />
<p:column headerText="الحالة" >
<h:outputText value="#{interval3.state3}" />
</p:column>
<p:column headerText="المعلم" >
<h:outputText value="#{interval4.teachers4}" />
</p:column>
<p:column headerText="الماده" />
<p:column headerText="الحالة" >
<h:outputText value="#{interval4.state4}" />
</p:column>
<p:column headerText="المعلم" >
<h:outputText value="#{interval5.teachers5}" />
</p:column>
<p:column headerText="الماده" />
<p:column headerText="الحالة" >
<h:outputText value="#{interval5.state5}" />
</p:column>
<p:column headerText="المعلم" >
<h:outputText value="#{interval6.teachers6}" />
</p:column>
<p:column headerText="الماده" />
<p:column headerText="الحالة" >
<h:outputText value="#{interval6.state6}" />
</p:column>
<p:column headerText="المعلم" >
<h:outputText value="#{interval7.teachers7}" />
</p:column>
<p:column headerText="الماده" />
<p:column headerText="الحالة" >
<h:outputText value="#{interval7.state7}" />
</p:column>
</p:row>
</p:columnGroup>
<f:facet name="footer">
اجمالي عدد الاستعلامات #{fn:length(tableBean.carsSmall)}
</f:facet>
</p:dataTable>
</p:scrollPanel>
<br />
<h:commandButton value="طباعة التقرير" type="button"
icon="ui-icon-print">
<p:printer target="hesham" />
</h:commandButton>
</h:form>
Um.. you simply don't have a table body here. Everything you have is an enormous header, incorrectly referencing the iteration variable and a giant footer.
See this example for how it's done properly, the p:columnGroup only enclosing the header:
<p:dataTable id="salesTable" var="sale" value="#{tableBean.sales}">
<f:facet name="header">
Sales/Profits of Manufacturers
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="Manufacturer" />
<p:column colspan="2" headerText="Sales" />
</p:row>
<p:row>
<p:column headerText="Sales Count" />
<p:column headerText="Profit" />
</p:row>
</p:columnGroup>
<p:column>
#{sale.manufacturer}
</p:column>
<p:column>
#{sale.lastYearProfit}%
</p:column>
</p:dataTable>