Data Exporting in JSF Using PrimeFaces
Introduction
In this article we shall learn how to export the jsf data table content from the web page to a pdf, xls, xml and csv format in a JSF application, that may be very useful while generating a report . Now we are going to use a component library named Primefaces, which has more than 70+ ajax powered components that enriches our web application with rich look and feel. So here we are going to invoke a Primefaces component named Data Exporter which is used to export the datas in the web page to a pdf, xls, xml and csv format. I am damn sure, Primefaces reduces the complexity for the developers while constructing a report for a web application.
Nice Example. But can the scope be page instead of session for DataExporterBean (as normally we dont store data of this kind in session)?
Hi karthi,
Thanks for your valuable comment. Page scope exists only in JSP, but JSF has only four scopes they are none, request, session and application. You may also use request scope for my example. I hope the following link would be helpful
http://www.java-samples.com/showtutorial.php?tutorialid=472
Thanks for the reply. Good to know that we cannot specify page scope as I have never worked with vanilla JSF. I use Seam framework and has the privilege of using PAGE scopetype
you’re welcome. Thanks for you comment!!
Cool stuff! Thanks for putting this up.
I need to meet a wonderful programmer, who can solve this problem…
I try to use itext 2.1.7 jar file to convert jsp posted files to pdf.. but it generates error…
my source code…
OutputStream file=response.getOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
document.add(new Paragraph(“Name: “+request.getParameter(“nam”)));
document.add(new Paragraph(“Sex: “+request.getParameter(“sex”)));
document.add(new Paragraph(“Age: “+request.getParameter(“age”)));
document.close();
file.close();
it’s output ….
%PDF-1.4 %���� 2 0 obj stream x�+�r �26S�00SI�2P�5��1���BҸ4�sS��S�R5C��JPTj�VX)�b�rL�L-/*,/B�w � ����� endstream endobj 4 0 obj <<>>/MediaBox[0 0 595 842]>> endobj 1 0 obj endobj 3 0 obj endobj 5 0 obj endobj 6 0 obj endobj xref 0 7 0000000000 65535 f 0000000324 00000 n 0000000015 00000 n 0000000412 00000 n 0000000167 00000 n 0000000475 00000 n 0000000520 00000 n trailer <]/Root 5 0 R/Size 7/Info 6 0 R>> startxref 630 %%EOF
i know, u can solve this… tanks alot….
Really Good Article.
I havent try this yet but just wanted to confirm is this export link (CSV, PDF,XML) will download the whole data available in the list or it would be just the one which is displayed on the page in tabular format.
Hi Nishant,
Thanks for ur comments, Its realy useful both the options availble to generate a report for paricular page or all the available page you may go through this
http://97.107.138.40:8080/prime-showcase/ui/exporter.jsf
it may helps ……..
Hi Shunmugakrishna,
Thnxs for your prompt response !!
I will definately try this approach for my project.
Hi shunmuga,
In ur example u have one datatable, but in my requirement i have two datatables and some static text also the and i am using H:DATATABLE instead of P:DATATABLE.Can you help me to implement my case. my page looks as below
You have requested to following things
NAME Description FEE Fee
Gowri123 123m NA $3.21
You have requested to unsubscribe the following value added services
NAME
gowwi
gavi
gowri
The update of Value will take effect in 1 working day.
Hi shunmuga,
In ur example u have one datatable, but in my requirement i have two datatables and some static text also the and i am using H:DATATABLE instead of P:DATATABLE.Can you help me to implement my case. my page looks as below
You have requested to following things
NAME Description FEE Fee
Gowri 123 123m NA
You have requested to unsubscribe the following value added services
NAME
gowwi
gavi
gowri
The update of Value will take effect in 1 working day.
pls help me to generate it as PDF. ur help will be really appriciate.
Hi Shunmuga,
Here is my jsp page cod
and my managedbeans are under session scope, i cann’t change the scope since my project is currently in Production.
Hi Shunmuga,
Pls advice me on my case. it is a bit urgent.
Hi I have some Issue With Export My datable contain Link So whenever m trying to Export data ..data is look like this…….
“Company”,”Buy/Sell”,”Investor”,”Txn Date”,”Avg. Price”,”Txn Quantity”
“/test/company/Acropetal Technologies Ltd/7439″,”Buy”,”Basmati Securities Pvt Ltd”,”2011-09-08″,”15.24″,”215829″
“/test/company/Acropetal Technologies Ltd/7439″,”Sell”,”Basmati Securities Pvt Ltd”,”2011-09-08″,”15.05″,”215829″
“/test/company/Amrutanjan Health Care Ltd/74″,”Buy”,”A K G Securities And Consultancy ltd”,”2011-09-07″,”851.12″,”36068″
As u seen in Company Name “test/company/” This is also added which is not required Please Let me Know How to Resolve this Issue