dataexporter primefaces not working - jsf

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.

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.

How to update PrimeFaces datatable using poll with updated toggled columns

I've been working on a jsf project(using primefaces 5.2). I've a datatable which gets updated using a poll in every 10 seconds.I also have a column toggler. Everything is working fine but the only problem is that when poll updates the datatable it again adds all the columns to the table.Is there some way to restrict datatable to only show the selected toggled columns only even after poll update.
Here is My xhtml code
<h:form rendered="#{bean.value!=null}" >
<p:dataTable id="tab" var="var" value="#{bean.value}" >
<f:facet name="header">
Header for dataTable
<p:commandButton style="float:right" id="toggler" type="button" value="Columns" icon="ui-icon-calculator" />
<p:columnToggler datasource="tab" trigger="toggler" />
</f:facet>
<p:column>
<f:facet name="header"><h:outputText value="Start"/>
</f:facet>
<h:outputText value="#{var.startTime}">
<f:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="End"/>
</f:facet>
<h:outputText value="#{var.endTime}" >
<f:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{var.name}" >
</h:outputText>
</p:column>
</p:dataTable>
<p:poll interval="10" update="tab" />
</h:form>

Primefaces data exporter exports empty values in 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

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

Primefaces 3.0 DataTable inCell editing , RowEditEvent doesn't retrieve updated field

I am working on a sample app with primefaces 3 , using datatables incell editing mode. Although when i edit , i see the event.getObjects gives me the object which is not modified.
Changed the property of the object on debug mode, it does update.
So i couldn't figure out why i cant get the edited property.
Below are my eventlistener method and the xhtml;
Any pointers are welcomed
Thanks in advance
EventListener
public void editListener(RowEditEvent event){
System.out.println("EDIT LISTENER");
update((Employer)event.getObject());
}
JSF :
<h:form id="form">
<h1><h:outputText value="List"/></h1>
<p:dataTable value="#{employer.employers}" var="item" paginator="true" rows="10" style="width:300px">
<p:column>
<f:facet name="header">
<h:outputText value="Id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.name}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.name}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Surname"/>
</f:facet>
<h:outputText value="#{item.surname}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Phone"/>
</f:facet>
<h:outputText value="#{item.phone}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
<p:column headerText="Options" style="width:50px">
<p:rowEditor />
</p:column>
<p:ajax event="rowEdit" listener="#{employer.editListener}"></p:ajax>
</p:dataTable>
</h:form>
After this...
<p:dataTable value="#{employer.employers}" var="item" paginator="true"
rows="10" style="width:300px">
...put the following:
<p:ajax event="rowEdit" update="#this" listener="#{HandlerClassName.rowEditListener}" />

Resources