I have an List of List. lets say student and address. one to many relationship. In my data table there are 3 columns for the Name, Surname, Age related to the Student and In a single column I need to show address with concatenating the following fields like, address1, address2, city, country.Now I need to export this table by using <p:dataExporter>. When I try to export as Excel the corresponding column of Address is exported as Object (org.primefaces.uirepeat. blah blah..)
My code is
<p:dataTable value="#{manager.studentList}" var="item" id="studentData">
<p:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{item.name}" />
</p:column>
<p:column>
<f:facet name="header">Surname</f:facet>
<h:outputText value="#{item.surname}" />
</p:column>
<p:column>
<f:facet name="header">Age</f:facet>
<h:outputText value="#{item.age}" />
</p:column>
<p:column>
<f:facet name="header">Address</f:facet>
<ui:repeat value="#{studentBean.addressList}" var="address">
<h:outputText value="#{address.address1}" /> <br />
<h:outputText value="#{address.address2}" /> <br />
<h:outputText value="#{address.city}" /> <br />
<h:outputText value="#{address.country}" />
</ui:repeat>
</p:column>
</p:dataTable>
<h:commandLink>
<p:graphicImage name="/images/excel.png" />
<p:dataExporter type="xls" target="studentData" fileName="studentdetails" pageOnly="true"/>
</h:commandLink>
Suggest me some way to export. even I tried with c:forEach and columns.
<p:dataTable value="#{manager.studentList}" rowIndexVar="index" var="item" id="studentData">
<p:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{item.name}" />
</p:column>
<p:column>
<f:facet name="header">Surname</f:facet>
<h:outputText value="#{item.surname}" />
</p:column>
<p:column>
<f:facet name="header">Age</f:facet>
<h:outputText value="#{item.age}" />
</p:column>
<p:column>
<f:facet name="header">Address</f:facet>
<c:forEach var="address" items="#{studentBean.addressList.get(index).address}">
<h:outputText value="#{address.address1}" />,
<h:outputText value="#{address.address2}"/>,
<h:outputText value="#{address.city}" />,
<h:outputText value="#{address.country}" />
</c:forEach>
</p:column>
</p:dataTable>
<h:commandLink>
<p:graphicImage name="/images/excel.png" />
<p:dataExporter type="xls" target="studentData" fileName="studentdetails" pageOnly="true"/>
</h:commandLink>
i trying with c:forEach is ok
Related
I am developing web using PrimeFaces 6.0 components. On
<p:dataTable> component when we set scrollable="true" option, columns headers alignment goes wrong.
Following is my code snippet:
<p:fieldset legend="Machine Test Match" id="panel233" toggleable="true" toggleSpeed="500" >
<!--<p:panel id="panel233" header=" Machine Test Match" style="height:325px;border: none">-->
<p:dataTable id="testmatchtable" var="testMatchvalues" value="#{manufactureBean.listTestMatchata}" filteredValue="#{manufactureBean.filteredManufacture}" editable="true"
styleClass="mystyle" tableStyle="table-layout:auto;width:100% important!;" rowKey="#{testMatchvalues.testId}" scrollRows="10" scrollable="true" scrollHeight="230" rows="40" liveScroll="true" selection="#{manufactureBean.testMatchModel}" selectionMode="single" resizableColumns="true" >
<p:column headerText="Test ID" filterBy="#{testMatchvalues.testId}" filterMatchMode="contains" style="width:35px">
<h:outputText value="#{testMatchvalues.testId}" />
</p:column>
<p:column headerText="Test Desc" filterBy="#{testMatchvalues.testDesc}" filterMatchMode="contains" style="width:35px" >
<h:outputText value="#{testMatchvalues.testDesc}" />
</p:column>
<p:column headerText="Specimen Desc" filterBy="#{testMatchvalues.specimenDesc}" filterMatchMode="contains" style="width:35px" >
<h:outputText value="#{testMatchvalues.specimenDesc}" />
</p:column>
<p:column headerText="Path Test Desc" filterBy="#{testMatchvalues.pathTestDesc}" filterMatchMode="contains" style="width:35px">
<h:outputText value="#{testMatchvalues.pathTestDesc}" />
</p:column>
<p:column headerText="Path Param Name" style="width:35px" filterBy="#{testMatchvalues.parameterName}" filterMatchMode="contains">
<h:outputText value="#{testMatchvalues.parameterName}" />
</p:column>
<p:column headerText="Additional Factor" style="width:35px" >
<h:outputText value="#{testMatchvalues.additionFactor}" />
</p:column>
<p:column headerText="Multiply Factor" style="width:35px">
<h:outputText value="#{testMatchvalues.multiplyFactor}" />
</p:column>
<p:column headerText="Machine Host Code" style="width:35px">
<h:outputText value="#{testMatchvalues.machineHostCode}" />
</p:column>
<p:column headerText="Active" style="width:35px">
<h:outputText value="#{testMatchvalues.active}" />
</p:column>
</p:dataTable>
<!--</p:panel>-->
</p:fieldset>
Code taken from https://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml
Attached image shows the problem clearly as column headers and data is not aligned properly.
Image link
For p:column, width="4%" works for me rather than using '4px'
Hello everybody i have tabview:
<p:tabView value="#{beanPlanning.plannings}"
var="planning" id="tabview"
widgetVar="myTabView"
activeIndex="#{beanPlanning.index}"
cache="false"
>
<p:ajax event="tabChange" process="#this" listener="#{beanPlanning.elementSelected(planning.id)}" update="tabview"/>
<p:tab title="#{planning.libelle}" >
<p:panelGrid>
<ui:repeat value="#{beanPlannin.tasksFactorys}" var="tf">
<p:row>
<p:column>
<h:outputText value="#{tf.libelle}"/>
</p:column>
<p:column>
<p:selectBooleanCheckbox value="#{tf.affiche}" />
<h:outputText value="#{messages.PFafficheCheckox}" />
</p:column>
<p:column>
<p:colorPicker value="#{tf.coleur}" />
</p:column>
...
but when I want to save data it's possible save just the data of last tab!!!
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
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)
can we do a internal sorting in primeface datetable ? If i have column a ,b ,c. can i sort the column c and then internally by column b in p:dataTable.
<h:form>
<p:dataTable var="car" value="#{tableBean.carsSmall}">
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="a">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="b">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="c">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
</h:form>
Yes, you can. http://www.primefaces.org/showcase/ui/datatableSortingMultiple.jsf
P.S Don't forget pressing CTRL or Cmd :)