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>
Related
I am trying to show a total value on my dataTable, my code is similar to the primefaces showcase DataTable - SummaryRow and still not working.
<p:dataTable id="dtCaixa" var="list" value="#{caixaMB.list}" paginator="true" rows="7"
paginatorPosition="bottom" rowsPerPageTemplate="10,15,20" liveScroll="true"
paginatorAlwaysVisible="false" emptyMessage="Nenhuma entrada!" liveResize="true">
<p:column headerText="Nome" sortBy="#{list.produtoFK.nome}" style="width:15%;">
<h:outputText value="#{list.produtoFK.nome}" />
</p:column>
<p:column headerText="Funcionário" sortBy="#{list.funcionarioFK.nome}">
<h:outputText value="#{list.funcionarioFK.nome}" />
</p:column>
<p:column headerText="Quantidade" sortBy="#{list.quantidade}">
<h:outputText value="#{list.quantidade}" />
</p:column>
<p:column headerText="Preço" >
<h:outputText value="#{list.produtoFK.preco}" rendered="#{not empty list.produtoFK}">
<f:convertNumber pattern="R$ #0.00" locale="pt_BR"/>
</h:outputText>
</p:column>
<p:column headerText="Total" sortBy="#{list.total}" >
<h:outputText value="#{list.total}" >
<f:convertNumber pattern="R$ #0.00" locale="pt_BR"/>
</h:outputText>
</p:column>
<p:column headerText="Remover" class="centered">
<p:commandButton icon="ui-icon-trash" title="excluir" onclick="PF('confirmaExclusao').show();">
<f:setPropertyActionListener target="#{caixaMB.itemSelecionado}" value="#{list}" />
</p:commandButton>
</p:column>
<p:summaryRow>
<p:column colspan="3" style="text-align:right">
<h:outputText value="Total:" />
</p:column>
<p:column>
<h:outputText value="#{caixaMB.total}">
</h:outputText>
</p:column>
</p:summaryRow>
</p:dataTable>
Does anybody have any idea why is this happening?
You need to sort the dataTable using at least one column if you want to use summaryRow. Check the Primefaces documentation.
E.g. put the attribute sortBy="#{myList.myOrderValue}" on the <p:datatable> tag.
I think what you're trying to achieve is the overall total of the column showing up at the bottom. I was caught out by the summaryRow function too, until I realised it was a grouping function and not a totalling summary. What I did you get around this was for the last column I added some footerText. You will have to calculate your totals manually (iterate over your dataset etc), then you can use something like:
<p:column style="text-align: right" footerText="$ #{invoicesbean.total}">
<f:facet name="header">
<h:outputText value="Amount" />
</f:facet>
........ etc
This worked well for me but YMMV!
The data in the following picture is dynamic & that is not looking good actually.
I want to fix the width for these columns.
<p:row styleClass="ui-panelgrid-cell" rowspan="2">
<p:column>
<div style="overflow: auto; width: 100%;">
<p:dataTable var="tPreferences"
value="#{userPreferences.preferences}"
emptyMessage="No Questions Found." id="pTable" styleClass="borderless">
<p:column headerText="PREFERENCES">
<h:outputText id="sName" styleClass="cellLabelMand"
value="#{tPreferences.shortText}" />
<h:outputText value="<br/><br/>" escape="false" />
<h:selectManyCheckbox id="grid"
value="#{tPreferences.preferencesSelectedItem}"
layout="grid" columns="1">
<f:selectItems value="#{tPreferences.catList}" var="pref" />
</h:selectManyCheckbox>
</p:column>
</p:dataTable>
</div>
</p:column>
</p:row>
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 am having trouble updating components in primefaces. Here is one example:
<h:form>
<p:panel style="width: 350px;" header="Partial Process">
<p:dataTable id="tablaPersonas" var="per" value="#{manejador.lista}">
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{per.nombre}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Apellido" />
</f:facet>
<h:outputText value="#{per.apellido}" />
</p:column>
<p:column headerText="Editar" style="text-align: center;">
<p:commandButton value="Editar"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton value="Abrir" onclick="widgetDlgAgregar.show();"/>
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250" height="150" closable="true">
<h:panelGrid id="gridAdd" columns="2">
<h:outputLabel value="Nombre:"/>
<p:inputText value="#{manejador.auxiliarAgregar.nombre}"/>
<h:outputLabel value="Apellido:"/>
<p:inputText value="#{manejador.auxiliarAgregar.apellido}"/>
<p:commandButton oncomplete="widgetDlgAgregar.hide();" update="tablaPersonas,gridAdd" value="Agregar" actionListener="#{manejador.agregarPersona}"/>
</h:panelGrid>
</p:dialog>
</h:form>
As you see, I click on a CommandButton called "Abrir" and a Dialog opens with "Agregar" as title. I fill in the input boxes and when I click the CommandButton "Agregar", the DataTable isn't updated. Why is this happening?
Oh sorry i think you forgot this update
try this it should work
<h:form prependId="false">
<p:panel style="width: 350px;" header="Partial Process">
<p:dataTable id="tablaPersonas" var="per"
value="#{manejador.lista}">
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{per.nombre}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Apellido" />
</f:facet>
<h:outputText value="#{per.apellido}" />
</p:column>
<p:column headerText="Editar" style="text-align: center;">
<p:commandButton value="Editar" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton value="Abrir" onclick="widgetDlgAgregar.show();" update="gridAdd" />
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250"
height="150" closable="true">
<h:panelGrid id="gridAdd" columns="2">
<h:outputLabel value="Nombre:" />
<p:inputText value="#{manejador.auxiliarAgregar.nombre}" />
<h:outputLabel value="Apellido:" />
<p:inputText value="#{manejador.auxiliarAgregar.apellido}" />
<p:commandButton oncomplete="widgetDlgAgregar.hide();"
update="tablaPersonas,gridAdd" value="Agregar"
actionListener="#{manejador.agregarPersona}" />
</h:panelGrid>
</p:dialog>
</h:form>
try to put your
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250" height="150" closable="true">
outside the form and add prependId="false" to your form <h:form prependId="false" >
I have problem with datatable using Primefaces 2.2.1 and JSF 2.0.
I have used filtering and paging in the datatable. When I try to filter the selected data is displayed and when i remove the filter the entire data is displayed. But after this when i try to use paging then suddendly all the rows becomes blank(empty)
See screenshot below
Any suggestions. Please help.
.xhtml file
<p:dataTable var="user" value="#{userManagedBean.searchUsersResults}"
selection="#{userManagedBean.selectedUser}" selectionMode="single"
dynamic="true"
onRowSelectUpdate="userUpdateForm"
onRowUnselectUpdate="userUpdateForm"
rowSelectListener="#{userManagedBean.onUserSelect}"
rowUnselectListener="#{userManagedBean.onUserUnselect}"
paginator="true" rows="10" style="width: 70% ">
<p:column sortBy="#{user.userId}" filterBy="#{user.userId}" >
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{user.userId}" />
</p:column>
<p:column sortBy="#{user.username}" filterBy="#{user.username}">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.username}" />
</p:column>
<p:column sortBy="#{user.emailId}" filterBy="#{user.emailId}">
<f:facet name="header">
<h:outputText value="Email" />
</f:facet>
<h:outputText value="#{user.emailId}" />
</p:column>
<p:column sortBy="#{user.dob}" filterBy="#{user.dob}">
<f:facet name="header">
<h:outputText value="DOB" />
</f:facet>
<h:outputText value="#{user.dob}" >
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
</p:column>
</p:dataTable>
<p:panel id="userDetailsPanelId" header="Users Details" style="width:60%;">
<h:panelGrid columns="2" cellpadding="2" id="userUpdateForm" border="0" >
<h:outputLabel for="#{userManagedBean.selectedUser.userId}" value="UserId"/>
<h:inputText value="#{userManagedBean.selectedUser.userId}" style="width: 100%;" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.username}" value="Username"/>
<h:inputText value="#{userManagedBean.selectedUser.username}" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.emailId}" value="EmailId"/>
<h:inputText value="#{userManagedBean.selectedUser.emailId}" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.gender}" value="Gender"/>
<h:inputText value="#{userManagedBean.selectedUser.gender}" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.dob}" value="DOB"/>
<h:inputText value="#{userManagedBean.selectedUser.dob}" readonly="true">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:inputText>
</h:panelGrid>
</p:panel>
</h:form>
</center>
I encountered the same problem and eventually discovered it was caused by my value object (in this case your user object) not implementing Serializable.
I'm pretty sure that this known issue has been resolved in both the 2.2.RC and the 2.2 final. I suggest updating your jar file.