PrimeFaces DataExporter for DataTable inside TabView - primefaces

PF 8.0 JSF 2.2: I'm using DataTable inside Tabview, I'm facing issue in DataExporter that it's exporting all tables together even when I target it using #parent..:#child(0).
<p:tabView value="#{homeMB.users}" var="user" dynamic="true" id="tbview"
cache="true" scrollable="true" style="background:transparent">
<p:ajax event="tabChange" listener="#{homeMB.onTabChange}" />
<p:tab>
<f:facet name="title">
<span style="font-size:large">#{user.userId}</span>
</f:facet>
<p:dataTable var="c"
multiViewState="true" value="#{homeMB.model}" rows="10"
rowKey="#{c.id}" lazy="true" paginator="true"
paginatorPosition="bottom" styleClass="no-border"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} {Exporters}"
currentPageReportTemplate="[{startRecord}-{endRecord} of {totalRecords}]"
rowsPerPageTemplate="10,20,30,40,50" rowIndexVar="inx">
<f:facet name="{Exporters}">
<div style="float: right; padding-top: 5px;">
<h:commandLink title="Export to Excel">
<p:graphicImage name="/images/excel.png" width="24" />
<p:dataExporter type="xls" target="#parent:#parent:#child(0)"
fileName="Invoice(s)" />
</h:commandLink>
</div>
</f:facet>
............
</p:tab>
</p:tabView>

Did you try setting id on table you want to export, and then setting target as id of target table. Example:
<p:datatable id="first".../>
<p:dataExporter type="xls" target="first" fileName="Invoice(s)" />

Related

dataTable inside accordion doesn't update after client filter

I use primefaces in my project and i'm facing some issues with it's components.
I have a dataTabe inside an accordion and both of them are populated with a list in my managed bean. The thing is, before I put this dataTable inside the accordion the filter used to work just fine. When it was into the accordion, actualy the results were corresponding to the filter, but if I click on a comandButton in any row the object that I get from the "f:setPropertyActionListener" is not corresponding to the list after the filter.
Edit:
-Primefaces 6.0
-Dynamic Web Module 3.0
-Java 1.7
-Mojarra JSF Implementation 2.2.3
The .xhtml:
<h:form id="frmPrincipal" enctype="multipart/form-data">
<p:toolbar style="background : none; border:0px">
<f:facet name="left">
<p:commandButton value="Novo Documento" oncomplete="PF('dlgIncluirDocumento').show();"
actionListener="#{MyBean.prepararInclusao()}" update=":frmIncDocVal:pngIncDoc
:frmIncDocVal:pnlTblEmail :frmIncDocVal:pnlEmailNvDoc" />
</f:facet>
</p:toolbar>
<p:accordionPanel dynamic="true" value="#{MyBean.grupos}" var="grupo">
<p:tab title="#{grupo.nome}">
<p:dataTable id="tbValidadeDocFiltrado" widgetVar="#{grupo.idComponente}"
emptyMessage="Nenhum registro enccontrado" lazy="false"
value="#{grupo.documentos}" var="item" filteredValue="#{grupo.documentosFiltrados}"
paginator="true" rows="30" paginatorPosition="bottom" rowsPerPageTemplate="15,30,45">
<f:facet name="header"><p:outputLabel value="Validade Documento" /></f:facet>
<p:column headerText="Empresa" sortBy="#{item.tipoDocumento.empresa.nome}" filterBy="#{item.tipoDocumento.empresa.nome}">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('#{grupo.idComponente}').filter()" >
<f:selectItem itemLabel="Selecione" itemValue="#{null}"
noSelectionOption="true" />
<f:selectItems value="#{MyBean.itensEmpresa}"
var="empresa" itemValue="#{empresa.nome}"
itemLabel="#{empresa.nome}" />
</p:selectOneMenu>
</f:facet>
<p:outputLabel value="#{item.tipoDocumento.empresa.nome}" />
</p:column>
<p:column headerText="Departamento"
sortBy="#{item.tipoDocumento.departamento.nome}"
filterBy="#{item.tipoDocumento.departamento.nome}">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('#{grupo.idComponente}').filter()">
<f:selectItem itemLabel="Selecione" itemValue="#{null}"
noSelectionOption="true" />
<f:selectItems value="#{MyBean.itensDepartamento}"
var="departamento" itemValue="#{departamento.nome}"
itemLabel="#{departamento.nome}" />
</p:selectOneMenu>
</f:facet>
<p:outputLabel value="#{item.tipoDocumento.departamento.nome}" />
</p:column>
<p:column headerText="Documento" sortBy="#{item.tipoDocumento.nome}"
filterBy="#{item.tipoDocumento.nome}">
<p:outputLabel value="#{item.tipoDocumento.nome}" />
</p:column>
<p:column headerText="Arquivo">
<p:commandLink title="Download" value="#{item.arquivo.nome}" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);" rendered="#{item.cadastroDocumentoDownload}" disabled="#{ ! item.icArquivo}">
<f:setPropertyActionListener value="#{item}" target="#{MyBean.validadeDocumento}" />
<p:fileDownload value="#{MyBean.fileDown}" />
</p:commandLink>
</p:column>
<p:column headerText="Opções" exportable="false" width="160">
<p:commandButton icon="ui-icon-pencil" title="Alterar"
oncomplete="PF('dialog1').show();"
disabled="false" rendered="#{item.cadastroDocumentoEditar}"
action="#{MyBean.prepararAlterarTipoDocumento()}"
update=":idTituloTpDocTituloTelaDlgAlt :frmAltTpDoc:pngAltDoc">
<f:setPropertyActionListener value="#{item}" target="#{MyBean.validadeDocumento}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:tab>
</p:accordionPanel>
</h:form>
Print with the command button working:
Print with the command button not working after filter:

Update <p:dialog> whenever new dialog box open in PrimeFaces

It keeps showing the previous value instead of the new one.
<p:panel id="instantTransPanel" header="Quick Transfer (To Beneficiary)" toggleable="true" closable="false" toggleSpeed="500" closeSpeed="500" widgetVar="instantTransPanelVar"
rendered="#{userMBean.loggedOnUser.customer.customerType != constantuserMBean.getFETSTYPE() and (userMBean.loggedOnUser.customer.customerType != constantuserMBean.getMERCHANTTYPE() or (userMBean.loggedOnUser.customer.customerType == constantuserMBean.getMERCHANTTYPE() and userMBean.loggedOnUser.customer.hasCustomerCapability))}">
<p:commandButton value="Add New Beneficiary" onclick="addBendlg.show();" />
<br/><br/>
<p:dataTable id="beneficiariesTable" var="obj" value="#{userMBean.loggedOnUser.customer.customerBeneficiaryList}"
paginator="true" rows="20"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100" style="width:100%" resizableColumns="true">
<p:column sortBy="#{obj.beneficiaryMsisdn}" headerText="Mobile Number" filterBy="#{obj.beneficiaryMsisdn}" filterMatchMode="contains">
<h:outputText value="#{obj.beneficiaryMsisdn}" />
</p:column>
<p:column sortBy="#{obj.beneficiaryName}" headerText="Name" filterBy="#{obj.beneficiaryName}" filterMatchMode="contains">
<h:outputText value="#{obj.beneficiaryName}" />
</p:column>
<p:column sortBy="#{obj.crt_dt}" headerText="Date Added">
<h:outputText value="#{obj.crt_dt}" />
</p:column>
<p:column headerText="Transfer">
<p:commandButton value="Transfer" update=":form:transferBenPanel" action="#{engineMBean.initTransfer(obj.beneficiaryMsisdn, obj.beneficiaryName)}" oncomplete="transferToBendlg.show();" />
</p:column>
<p:column headerText="Delete">
<p:commandButton ajax="false" onclick="return confirm('Are you sure?');" action="#{userMBean.deleteBeneficiary(obj.beneficiaryMsisdn)}" icon="ui-icon-close" style="margin:0"/>
</p:column>
</p:dataTable>
</p:panel>
After that it calls dialog and it works properly the first time but the next time I want to enter another value once clicked it pops up with the old values.
<p:dialog id="addBenDialog" header="Add Beneficiary" widgetVar="addBendlg" modal="true" dynamic="true" position="center">
<p:panelGrid columns="2" cellpadding="5" style="margin-bottom:10px;">
<f:facet name="header"></f:facet>
<h:outputLabel for="bmsisdn" value="Beneficiary Mobile Number: *" />
<p:inputText id="bmsisdn" value="#{userMBean.beneficiary.beneficiaryMsisdn}">
<p:ajax update="bname" />
</p:inputText>
<h:outputLabel for="bname" value="Beneficiary Name: " />
<h:outputText id="bname" value="#{userMBean.lookUpBeneficiaryName(userMBean.beneficiary.beneficiaryMsisdn)}" />
<f:facet name="footer">
<p:commandButton ajax="false" onclick="return confirm('Are you sure?');" action="#{userMBean.addBeneficiary}" value="Save" icon="ui-icon-disk" style="margin:0"/>
</f:facet>
</p:panelGrid>
</p:dialog>
You need to update the dialog box before it shows.
Change code as:
<p:commandButton value="Add New Beneficiary" onComplete="addBendlg.show(); update=:form:addBenDialog" />

PrimeFaces 3.2 dataExporter not working

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}" />

primefaces p:column exportOnly and exportable

I am using primefaces 3.2. And I need to use p:dataExporter. But parameters p:column exportable="false" and p:column exportOnly="true" does not works at all! What could be the reason of that?
Here is the code:
<p:dataExporter type="xls" target="dataTable" fileName="clients" postProcessor="#{clientBean.postProcessXLS}" />
<p:dataTable value="#{clientBean.model}" var="item" id="dataTable"
emptyMessage="#{messages['message.empty']}" styleClass="list"
paginator="true" rows="10" widgetVar="table"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="(#{messages['table.page.current']}: {currentPage} #{messages['table.totalpages']} {totalPages})"
rowsPerPageTemplate="5,10,15,25,50" paginatorPosition="bottom" paginatorAlwaysVisible="false">
<p:column exportOnly="true">
<f:facet name="header">
<h:outputText value="#{clients['clientNumber']}" />
</f:facet>
<h:outputText value="#{item.clientNumber}" />
</p:column>
<p:column sortBy="#{item.clientNumber}"
exportable="false" filterStyle="display:none;">
<f:facet name="header">
<h:outputText value="#{clients['clientNumber']}" />
</f:facet>
<h:outputLink value="#{request.contextPath}/admin/management/clients/clientInfo.jsf">
<f:param name="id" value="#{item.id}" />
<h:outputText value="#{item.clientNumber}" />
</h:outputLink>
</p:column>
First exportOnly attribute doesn't exist at all in p:column tag. exportable attribute is introduced in version 3.4, so it doesn't exist in your version (3.2).

Primefaces retrieve DataList or DataGrid value

I have the below dataList that displays images with pagination that shows one image at a time. I want to be able to know/retrieve what image is being displayed when I click my p:commandButton so that I can have access to it in my actionListener method (bookmarkletBean.update). Any ideas here?
<p:dataList value="#{bookmarkletBean.imageURLs}" var="img"
paginator="true" rows="1" effectSpeed="fast" pageLinks="4"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" paginatorPosition="bottom">
<p:column>
<p:graphicImage value="#{img}" width="200" height="110"/>
</p:column>
</p:dataList>
<p:commandButton styleClass="form-btn1" value="#{bundle['save.button.TEXT']}"
actionListener="#{bookmarkletBean.update}" oncomplete="bookmarkletAddedDlg.show()" />
Not Possible as both p:dataList and p:dataGrid dont have a selection property that can be attached to the backing bean your p:commandButton will belong to.
Therefore, I would recommend having a p:dataTable which does have the selection property, and once you click the button you will now which row (Image) was selected.
<p:dataTable value="#{bookmarkletBean.imageURLs}" var="img"
selection"#{bookmarkletBean.selectedImage}"
paginator="true" rows="1" effectSpeed="fast" pageLinks="4"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" paginatorPosition="bottom">
<p:column>
<p:graphicImage value="#{img}" width="200" height="110"/>
</p:column>
</p:dataTable>
<p:commandButton styleClass="form-btn1" value="#{bundle['save.button.TEXT']}"
actionListener="#{bookmarkletBean.update}" oncomplete="bookmarkletAddedDlg.show()" />
one possible solution was the below to arrange it like so with a link to select the wanted image and then the actionListener process's the selection
<p:dataTable value="#{bookmarkletBean.imageURLs}" var="img"
paginator="true" rows="1" effectSpeed="fast" pageLinks="4"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
paginatorPosition="bottom">
<p:column>
<p:graphicImage value="#{img}" width="200" height="110"/>
<p:commandLink>
<f:setPropertyActionListener value="#{img}" target="#{bookmarkletBean.selectedImage}"/>
select image
</p:commandLink>
</p:column>
</p:dataTable>