Why Prime Faces Data Table sorting not working - primefaces

I am new to prime faces and want to sort a data table using sort by and attributes but the table is not being sorted. I am using 5.3 PF.
<p:dataTable id="myTable"
styleClass="standardTable marginTopFive paddingBottom"
value="#{User.users}" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginatorPosition="bottom" rows="10" var="user"
emptyMessage="Error"
sortBy="#{user.userId}" sortOrder="descending">
<f:facet name="spacer">
<f:verbatim>
</f:verbatim>
</f:facet>
<f:facet name="footer">
</f:facet>
<p:column width="8%">
<f:facet name="header">
</f:facet>
<h:column>
<h:selectBooleanCheckbox
value="#{user.checked[user.userId]}" />
</h:column>
</p:column>
<p:column width="20%" sortBy="#{mpc.name}">
<f:facet name="header">
<h:outputText
value="User Name" />
</f:facet>
<h:outputText value="#{user.user_name}" />
</p:column>
<p:column width="30%" sortBy="#{mpc.email}">
<f:facet name="header">
<h:outputText
value="Email" />
</f:facet>
<h:outputText value="#{user.user_email}" />
</p:column>
</p:dataTable>

You set the name of the iterator variable as var="user", but here <p:column sortBy="#{mpc.name}"/> you called it as mpc.
So you must replace <p:column sortBy="#{mpc.name}"/> with <p:column sortBy="#{user.user_name}"/> and <p:column sortBy="#{mpc.email}"> with <p:column sortBy="#{user.user_email}">

Related

Primefaces Exporter Data type convert

We are using PrimeFaces http://www.primefaces.org/ to export data in different format, pdf,excel ...
but in Excel we got a issue with the data type, for example if the the data is Integer in the Excel document the value appears how String and the viewer suggest change the value to number
how could we change the Data type in the exporter process ?
Code
<p:dataTable value="#{reportsBean.data}" var="reportResultRec" widgetVar="resultWidgetVar" id="reportsResultId" paginator="true" rows="32" binding="#{reportsBean.dataTable}" >
<f:facet name="header">
<h:outputText value="Usage report"/>
</f:facet>
<p:column width="37%" styleClass="tdTreeStyle">
<f:facet name="header">
<h:outputText value="Titles"/>
</f:facet>
<h:outputText value="#{reportResultRec.Name}"/>
</p:column>
<p:column width="25%" styleClass="tdTreeStyle">
<f:facet name="header">
<h:outputText value="Full Name"/>
</f:facet>
<h:outputText value="#{reportResultRec.fullName}"/>
</p:column>
<p:column width="13%" styleClass="tdTreeStyle">
<f:facet name="header">
<h:outputText value="Updated Date"/>
</f:facet>
<h:outputText value="#{reportResultRec.Timestamp}">
<f:convertDateTime pattern="MM/dd/YY"/>
</h:outputText>
</p:column>
<p:column width="10%" styleClass="tdTreeStyle">
<f:facet name="header">
<h:outputText value="View Count"/>
</f:facet>
<h:outputText value="#{reportResultRec.viewCount}"/>
</p:column>
<p:column width="15%" styleClass="tdTreeStyle">
<f:facet name="header">
<h:outputText value="Recall Status"/>
</f:facet>
</p:column>
</p:dataTable>
<p:commandButton value="Export as Excel" ajax="false">
<p:dataExporter type="pdf" pageOnly="true" target="reportsResultId" fileName="Report"/>
</p:commandButton>
the reportResultRec.viewCount is convert to String and it is Integer and on the Excel viewer suggest change to Number

export text then datalist in excel and pdf with dataexporter

I am using primefaces 3.4.2 jar. I have a datatable with four columns. In two columns I have a datalist and I want to export text showed by datalist. But when I export it, it shows the following "org.primefaces.component.datalist.DataList#1195cc3" in the pdf and xls file.
<p:dataTable emptyMessage="#{messages['empty.result.set']}" id="searchResult" var="row" value="#{managePessoaJuridica.manageableList}" rows="10" paginator="true" paginatorPosition="top" paginatorAlwaysVisible="false" style="display:#{managePessoaJuridica.manageableList == null? 'none': ''}">
<p:column styleClass="column_icons" exportable="false">
<p:panelGrid columns="#{pessoaJuridicaController.showSelectAction?3:2}">
<p:commandButton id="selectAction" icon="ui-icon-circle-check" title="#{messages['action.select']}" action="#{pessoaJuridicaController.select(row.id)}" immediate="true" process="#this" rendered="#{pessoaJuridicaController.showSelectAction}"/>
<p:commandButton id="editAction" icon="ui-icon-pencil" title="#{messages['action.edit']}" action="#{pessoaJuridicaController.load(row.id)}" immediate="true" process="#this" update="#form"/>
<p:commandButton id="deleteAction" icon="ui-icon-trash" title="#{messages['action.delete']}" action="#{pessoaJuridicaController.delete(row.id)}" immediate="true" process="#this" update="searchResult"
onclick="return confirm('#{messages['confirm.delete.this']} #{messages['pessoa.juridica.view.title']}');" />
</p:panelGrid>
</p:column>
<p:column id="column_nome" sortBy="#{row.nome}" >
<f:facet name="header">
<h:outputText id="columnHeader_nome" value="#{messages['pessoa.nome']}"/>
</f:facet>
<h:outputText id="nome" value="#{row.nome}">
</h:outputText>
</p:column>
<p:column style="width:0px;">
<f:facet name="header">
<h:outputText id="columnHeader_categoriasPessoa" value="#{messages['pessoa.categorias.pessoa']}"/>
</f:facet>
<p:dataList type="definition" id="categoriasPessoa" var="item" value="#{row.categoriasPessoa}" >
<p:column>
<h:outputText id="item_categoriasPessoa" value="#{item}" converter="com.domain.configuracao.crud.CategoriaPessoaJsfConverter"/>
</p:column>
</p:dataList>
</p:column>
<p:column style="width:0px;">
<f:facet name="header">
<h:outputText id="columnHeader_identificacoesPessoa" value="#{messages['pessoa.identificacoes.pessoa']}"/>
</f:facet>
<p:dataList type="definition" id="identificacoesPessoa" var="item" value="#{row.identificacoesPessoa}">
<p:column>
<h:outputText id="item_categoriaIdentificacoes" value="#{pessoaJuridicaController.getCategoriaIdentificacao(item)}" converter="com.domain.configuracao.crud.CategoriaIdentificacaoJsfConverter"/>:
<h:outputText id="item_identificacoesPessoa" value="#{item}" converter="com.domain.configuracao.crud.IdentificacaoPessoaJsfConverter"/>
</p:column>
</p:dataList>
</p:column>
<p:column id="column_ativo" sortBy="#{row.ativo}" >
<f:facet name="header">
<h:outputText id="columnHeader_ativo" value="#{messages['classe.base.cadastro.ativo']}" />
</f:facet>
<h:outputText id="ativo" value="#{row.ativo}" converter="com.BooleanJsfConverter" >
</h:outputText>
</p:column>
<f:facet name="footer">
<p:menuButton value="#{messages['export.action']}" rendered="#{not empty managePessoaJuridica.manageableList}">
<p:menuitem value="#{messages['export.spreadsheet']}" ajax="false">
<p:dataExporter type="xls" target="searchResult" fileName="export" excludeColumns="0" encoding="ISO-8859-1"/>
</p:menuitem>
<p:menuitem value="#{messages['export.pdf']}" ajax="false">
<pe:exporter type="pdf" target="searchResult" fileName="export" excludeColumns="0" encoding="ISO-8859-1"/>
</p:menuitem>
<p:menuitem value="#{messages['export.csv']}" ajax="false">
<p:dataExporter type="csv" target="searchResult" fileName="export" excludeColumns="0" encoding="ISO-8859-1"/>
</p:menuitem>
</p:menuButton>
<p:spacer width="10"/>
<h:outputText value="#{fn:length(managePessoaJuridica.manageableList)} #{messages['records.found']}" rendered="#{not empty managePessoaJuridica.manageableList}"/>
</f:facet>
</p:dataTable>
But when I export it, it shows the following
"org.primefaces.component.datalist.DataList#1195cc3" in the pdf and
xls file.
Obviously, Primefaces's data exporter use the toString() method of an object to print its "value(s)".
Suggestions :
Write a custom exporter (recommended)
Override toString() method of org.primefaces.component.datalist.DataList (not advised)

call a method after the execution of the filtering of primefaces datatable

I have this datatable:
<p:dataTable id="tabla_gral" rendered="#{consumoMaterial.verTabla}" var="item" paginator="true" rows="15" rowKey="#{item.no}" value="#{consumoMaterial.listadoConsumo}" filteredValue="#{consumoMaterial.listadoConsumoFiltered}">
<p:ajax event="filter" listener="#{consumoMaterial.actualizarSaldos}" update=":form2:tabla_gral"/>
<f:facet name="header">
<h:outputText value="Búsqueda de Consumo por: #{consumoMaterial.tipoBuscar}: '#{consumoMaterial.codigo}'"/>
</f:facet>
<p:column exportable="#{consumoMaterial.no}" rendered="#{consumoMaterial.no}" id="cclave" sortBy="#{item.no}" filterBy="#{item.no}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Nro"/>
</f:facet>
<h:outputText value="#{item.no}"/>
</p:column>
<p:column exportable="#{consumoMaterial.centroCosto}" rendered="#{consumoMaterial.centroCosto}" id="cconcepto" sortBy="#{item.centroCosto}" filterBy="#{item.centroCosto}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Centro de Costo"/>
</f:facet>
<h:outputText value="#{item.centroCosto}"/>
</p:column>
<p:column exportable="#{consumoMaterial.codigoAlmacen}" rendered="#{consumoMaterial.codigoAlmacen}" id="ctipo" sortBy="#{item.codigoAlmacen}" filterBy="#{item.codigoAlmacen}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Almacén"/>
</f:facet>
<h:outputText value="#{item.codigoAlmacen}"/>
</p:column> </p:dataTable>
I want to call a method after the execution of the filtering of primefaces datatable,
I tested with
<p:ajax event="filter" listener="#{consumoMaterial.actualizarSaldos}" update=":form2:tabla_gral"/>
but when call actualizarSaldos listadoConsumoFiltered is null.

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).

How do I load rows into dataTable 2 when a row in dataTable 1 is clicked?

I have a form with a panel and two dataTables. The code below has had most of the columns removed to make it easier to follow.
<h:form id="invoiceLookUp">
<p:panel>
<f:facet name="header">
<p:column style="font-weight: bold;">
Invoice Selection Criteria
</p:column>
</f:facet>
<h:outputText value="Seq ID"/>
<p:inputText
id="invoice_header_seq_id" styleClass="field" size="10"
value="#{invoiceBean.invoice_header_seq_id}"
/>
<p:commandButton
update="invoicesTable" value="Look Up"
action="#{invoiceBean.addInvoices()}"
/>
</p:panel>
<p:dataTable
id="invoicesTable" var="invoice" rows="15" lazy="true" selectionMode="single"
value="#{invoiceBean.invoiceList}"
rowKey="#{invoice.invoiceHeader.invoiceHeaderSeqId}"
selection="#{invoiceBean.selectedInvoice}"
>
<p:ajax event="rowSelect" update=":invoiceLookUp:invoiceLinesTable"/>
<f:facet name="header"><h:outputText value="Invoice Headers" /></f:facet>
<p:column sortBy="#{invoice.invoiceHeader.invoiceHeaderSeqId}" id="invoiceSeqId">
<f:facet name="header">
<h:outputText value="Seq ID" title="Invoice Header Seq ID"/>
</f:facet>
<h:outputText value="#{invoice.invoiceHeader.invoiceHeaderSeqId}" />
</p:column>
</p:dataTable>
<p:dataTable
id="invoiceLinesTable" var="invoiceLine" rows="15" lazy="true" selectionMode="single"
value="#{invoiceBean.selectedInvoice.invoiceLines}"
rowKey="#{invoiceLine.invoiceLineSeqId}"
selection="#{invoiceBean.selectedInvoiceLine}"
>
<f:facet name="header"><h:outputText value="Invoice Lines" /></f:facet>
<p:column sortBy="#{invoiceLine.invoiceLineSeqId}" id="invoiceLineSeqId">
<f:facet name="header"><h:outputText value="Line Seq ID"/></f:facet>
<h:outputText value="#{invoiceLine.invoiceLineSeqId}"/>
</p:column>
</p:dataTable>
</h:form>
When you enter a Seq ID and then click Look Up, the table populates as expected. When I select a row in the invoicesTable, I get the following error:
javax.faces.FacesException: Cannot find component with identifier ":invoiceLookUp:invoiceLinesTable" referenced from "form:invoiceLookUp:invoicesTable".
Can anyone tell me what I am doing wrong?