Primefaces data exporter exports empty values in Excel - excel

I try to export some data loded from database.
With the code below, the exported file shows empty values in all columns althought my variable marchebean.selectedmarche.marchetraveau contains values.
Is there anything wrong in my code ?
I'm using Primefaces 4.0 and this is my xhtml page
<h:form id="form">
<p:tabView>
<p:tab title="Visualiser ">
<p:panel>
<h:commandLink >
<p:commandButton value="exporter" />
<p:dataExporter type="xls" target="crs" fileName="prixde" pageOnly="true" />
</h:commandLink>
<p:dataTable id="crs" var="marche" value="#{marchebean.selectedmarche.marchetraveau}" >
<f:facet name="header">
Tbaleau des travaux
</f:facet>
<f:facet name="footer">
<h3> Total HTVA = #{marchebean.calculdetotaltravhtva()}</h3>
<h3> Total TTC = #{marchebean.calculdetotaltravttc()} </h3>
</f:facet>
<p:column headerText="article" width="10%" >
<h:outputText value="#{marche.traveaux.article}"/>
</p:column>
<p:column headerText="Désignation des traveaux" width="40%" >
<h:outputText value="#{marche.traveaux.designation}"/>
<h:outputText value="#{marche.traveaux.paragraph}"/>
</p:column>
<p:column headerText="Unité">
<h:outputText value="#{marche.traveaux.unite}"/>
</p:column>
<p:column headerText="PUHTVA">
<h:outputText value="#{marche.prixunitaire}"/>
</p:column>
<p:column headerText="PUTTC">
<h:outputText value="#{marchebean.calcultva(marche.prixunitaire)}" />
</p:column>
<p:column headerText="Qtt">
<h:outputText value="#{marche.quantite}"/>
</p:column>
<p:column headerText="MHTVA">
<h:outputText value="#{marchebean.calculmonthtva(marche.prixunitaire ,marche.quantite)}" />
</p:column>
<p:column headerText="MTTC">
<h:outputText value="#{marchebean.calculmontttc(marche.prixunitaire ,marche.quantite)}" />
</p:column>
</p:dataTable>
</p:panel>
</p:tab>
</p:tabView>
</h:form>

we need to provide the
<f:facet name="header>
<h:outputText value="aricle"/>
</f:facet>
then exporter will add the headers to your exported document.
<p:column headerText="article" width="10%" >
<f:facet name="header">
<h:outputText value="article" />
</f:facet>
<h:outputText value="#{car.traveaux.article}"/>
</p:column>

This works for me. Maybe it needs validation and that's why it's empty at the end. Adding immediate="true" skips the validation.
<h:form id="confColaForm" .....>
<p:dataTable id="tablacolas" ... >
<f:facet name="header">
<h:commandLink id="exportar" update=":confColaForm:tablacolas" style="align:right;" immediate="true" >
<h:graphicImage library="images" name="iconexcel.png" style="width:30px;height:30px; "
title="Exportar" />
<p:dataExporter type="xls" target="tablacolas" fileName="ConfiguracionColas" />
</h:commandLink>
</f:facet>
...(columns here)
</p:dataTable/>
</h:form>

possible reason may be the "managedbean scope"...
1)change scope to "view"
2)serialize managedbean
this worked for me

Related

DataExporter tag - PrimeFaces - page only = "false"

I'm trying to export data from DataTable using DataExporter tag, but, DataExporter is exporting only first page data (page of the print), but I want to export data from all pages.
See below my button code and the screen.
Code:
<p:dataTable id="listaConsulta" rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'jsfcrud_odd_row' : 'jsfcrud_even_row'}" rowIndexVar="rowIx" value="#{funcionarioController.items}" var="item">
<p:column>
<f:facet name="header">
<h:outputText value="Código"/>
</f:facet>
<h:outputText value="#{item.codigo}"/>
</p:column>
<p:column width="25%">
<f:facet name="header">
<h:outputText value="Nome"/>
</f:facet>
<h:outputText value="#{item.nome}"/>
</p:column>
<p:column width="10%">
<f:facet name="header">
<h:outputText value="Cpf"/>
</f:facet>
<h:outputText value="#{item.cpf}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nascimento"/>
</f:facet>
<h:outputText value="#{item.datanascimento}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column width="25%">
<f:facet name="header">
<h:outputText value="Cargo"/>
</f:facet>
<h:outputText value="#{item.cargo.descricao}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Telefone"/>
</f:facet>
<h:outputText value="#{item.fone}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Celular"/>
</f:facet>
<h:outputText value="#{item.celular}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Ativo"/>
</f:facet>
<h:outputText value="#{item.estaAtivo}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<h:commandLink title="Editar" action="Create?faces-redirect=true&includeViewParams=true">
<f:setPropertyActionListener value="#{item}" target="#{funcionarioController.selected}"/>
<h:graphicImage height="32" value="/image/file_edit.png" />
</h:commandLink>
<h:commandLink title="Ficha Registro" target="_blank" action="#{funcionarioController.gerarRelatorioJasper}">
<f:setPropertyActionListener value="#{item}" target="#{funcionarioController.selected}"/>
<p:graphicImage value="/image/pdf.png" />
</h:commandLink>
</p:column>
</p:dataTable>
</h:panelGroup>
<br />
<p:commandButton ajax="false" immediate="true" action="#{funcionarioController.prepareCreate()}" value="#{bundle.ListFuncionarioCreateLink}"/>
<p:spacer width="10px"/>
<p:commandButton value ="Gerar Excel" ajax="false">
<p:dataExporter type="xls" target="listaConsulta" fileName="dadosFuncionarios" encoding="utf-8" pageOnly="false"/>
</p:commandButton>
Screen:
How do I solve this?
EDIT: I change the code inserting datatable and dataexporter entire code.

dataexporter primefaces not working

I am using PrimeFaces 5 and using dataexporter to export .xls and pdf file. When i click on export, nothing seems to be happening. Below is my code:
<h:body>
<h:form id="formReport">
<ui:include src="menu.xhtml"></ui:include>
<p:dataTable id="ngoReporttbl" var="obj" styleClass="datatable"
value="#{ngoReportController.ngoReportList}" >
<f:facet name="header">
List of Cars
<p:commandButton id="toggler" type="button" value="columns" style="float:right" icon="ui-icon-calculator"></p:commandButton>
<p:columnToggler datasource="ngoReporttbl" trigger="toggler"></p:columnToggler>
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="NGO Id"></h:outputText>
</f:facet>
<h:outputText value="#{obj.ngoId}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="NGO Name Org"></h:outputText>
</f:facet>
<h:outputText value="#{obj.ngoNameOrg}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Environment"></h:outputText>
</f:facet>
<h:outputText value="#{obj.environment}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Livelihood"></h:outputText>
</f:facet>
<h:outputText value="#{obj.livelihood}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Country"></h:outputText>
</f:facet>
<h:outputText value="#{obj.country}"></h:outputText>
</p:column>
</p:dataTable>
<h:commandLink style="float:right">
<p:graphicImage value="../images/pdf.png" width="45"></p:graphicImage>
<p:dataExporter type="pdf" target="ngoReporttbl" fileName="ngoReport" pageOnly="true"></p:dataExporter>
</h:commandLink>
<h:commandLink style="float:right">
<p:graphicImage value="../images/csv.png" width="45"></p:graphicImage>
<p:dataExporter type="xls" target="ngoReporttbl" fileName="ngoReport" pageOnly="true"></p:dataExporter>
</h:commandLink>
<ui:include src="footer.xhtml"></ui:include>
</h:form>
</h:body>
Both the dataTable and the Export command are within one form. It is similar to the example given on primefaces.org site. But, I'm unable to export data to pdf, cvs.
For XLS, you don't need anything extra. For PDF, you need POI. Primefaces only works with 2.1.7 due to licensing issues. And your commandButton / commandLink need to be ajax="false". Good luck.

primefaces dialog content is on page at the begining

Below is code of xhtml page,
even i put dialog in a form or not i can see outputtexts below of the page.
I am running into such situation for the first time.
<h:form id="form">
<h:outputLabel value="Welcome #{loginBean.name}"></h:outputLabel>
<p:dataTable id="cars" var="book" value="#{indexView.mediumBooksModel}" paginator="true" rows="10"
selection="#{indexView.selectedBook}" rowKey="">
<f:facet name="header">
RadioButton Based Selection
</f:facet>
<p:column selectionMode="single" style="width:2%" />
<p:column headerText="Title" style="width:25%">
#{book.title}
</p:column>
<p:column headerText="ISBN" style="width:25%">
#{book.isbn}
</p:column>
<p:column headerText="Year" style="width:24%">
#{book.year}
</p:column>
<p:column headerText="Price" style="width:24%">
#{book.price}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":displaySingle" oncomplete="singleBookDialog.show()"/>
</f:facet>
</p:dataTable>
</h:form>
<p:dialog id="dialog" header="Book Detail" widgetVar="singleBookDialog" resizable="false"
modal="true" >
<h:panelGrid id="displaySingle" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="/images/books/#{indexView.selectedBook.image}.jpg"/>
</f:facet>
<h:outputText value="Title:" />
<h:outputText value="#{indexView.selectedBook.title}" style="font-weight:bold"/>
<h:outputText value="Year:" />
<h:outputText value="#{indexView.selectedBook.year}" style="font-weight:bold"/>
<h:outputText value="ISBN:" />
<h:outputText value="#{indexView.selectedBook.isbn}" style="font-weight:bold"/>
<h:outputText value="Price:" />
<h:outputText value="#{indexView.selectedBook.price}" style="font-weight:bold"/>
</h:panelGrid>
</p:dialog>

Row expansion component submitting form on expansion when roweditor is present

My web page looks like this:
<h:form>
<p:dataTable var="car" value="#{tableBean.carsSmall}">
<f:facet name="header">
Expand rows to see detailed information
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column style="width:250px">
<f:facet name="header">
Model
</f:facet>
<h:outputText value="#{car.model}" />
</p:column>
<p:column style="width:250px">
<f:facet name="header">
Year
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:rowExpansion>
<p:fieldset legend="Detail">
<p:dataTable value="#{car.colors}" var="color">
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{color.disable}" />
</f:facet>
<f:facet name="input">
<h:selectBooleanCheckbox value="#{color.disable}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:fieldset>
</p:rowExpansion>
</p:dataTable>
</h:form>
This component is automatically updating the wrong values in database, for example it is setting false for the color.disable property upon just expanding the row.
I am using:
JSF 2.0.9
Primefaces 2.2.1

commandButton does not fire action

<h:form id="main_form">
<p:treeTable var="catalog" value="#{catalogSelectBean.root}" lazy="true" selection="#{myView.selectedCatalogNode}" selectionMode="single">
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{catalog.name}" />
</p:column>
<p:column width="100">
<f:facet name="header">
<h:outputText value="Desc"/>
</f:facet>
<h:outputText value="#{catalog.description}"/>
</p:column>
</p:treeTable>
<!-- The problem commandButton below-->
<p:commandButton action="#{myView.updateProductListForSelectedCatalog}"
update=":main_form:selectProductTable" value="Bring products">
</p:commandButton>
<!-- The problem commandButton above-->
<p:dataTable id="selectProductTable" var="product" value="#{myView.productDataModel}" paginator="true" selection="#{myView.selectedProduct}" >
<f:facet name="header">
Product Selection
</f:facet>
<p:column selectionMode="single" />
<p:column headerText="name">
<h:outputText value="#{product.name}" />
</p:column>
</p:dataTable>
<p:commandButton action="#{myView.setSelectedProductToForm}"
update="main_form"
value="Set">
</p:commandButton>
</h:form>
the problem commandButton does not fire action, if i had selected something in selectproducttable.

Resources