Home > Java, JSF, Primefaces > Data Exporting in JSF Using PrimeFaces

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.

Read the rest of this entry…

  1. November 27, 2009 at 10:53 pm | #1

    Nice Example. But can the scope be page instead of session for DataExporterBean (as normally we dont store data of this kind in session)?

  2. November 27, 2009 at 11:32 pm | #3

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

  3. December 2, 2009 at 10:48 pm | #5

    Cool stuff! Thanks for putting this up.

  4. semere(from Ethiopia)
    January 12, 2010 at 2:55 pm | #6

    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��J PTj�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….

  5. Nishant
    March 5, 2010 at 10:04 am | #7

    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.

  6. Nishant
    March 5, 2010 at 2:52 pm | #9

    Hi Shunmugakrishna,
    Thnxs for your prompt response !!
    I will definately try this approach for my project.

  7. gauri
    May 19, 2010 at 11:59 am | #10

    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.

  8. gauri
    May 19, 2010 at 12:05 pm | #11

    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.

  9. gauri
    May 19, 2010 at 1:04 pm | #12

    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.

  10. gauri
    May 20, 2010 at 9:34 am | #13

    Hi Shunmuga,

    Pls advice me on my case. it is a bit urgent.

  11. October 13, 2011 at 3:09 pm | #14

    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

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.