Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:54:05+00:00 2026-06-14T04:54:05+00:00

I would like to export the contents of a <rich:dataTable> or <rich:extendedDataTable> to excel.

  • 0

I would like to export the contents of a <rich:dataTable> or <rich:extendedDataTable> to excel.

  • I have see that PrimeFaces has the “exporter feature” http://www.primefaces.org/showcase/ui/exporter.jsf

  • I would like to be able to do something similar to this only with out using PrimeFaces, but with richFaces (version 3.3.3)…(I would like to migrate to RichFaces 4 at some point in the future but am stuck with 3.3.3 for now)

  • I have read that it is possible to build your own using http://poi.apache.org/ but I do not know where to start on implementing something like this…

Any thoughts about how best to preform the desired export and examples would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:54:06+00:00Added an answer on June 14, 2026 at 4:54 am

    Using POI in JSF isn’t really different from using POI in plain Java. Just have a collection of items representing each record. You must already have it as you’re using a datatable which also takes such a collection. You just have to iterate over exactly the same collection to create an excel sheet in POI.

    Here’s a kickoff example, where items is a List<Item> which you’re also using in the datatable:

    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet("sheet title");
    int rowIndex = 0;
    
    for (Item item : items) {
        Row row = sheet.createRow(rowIndex++);
        int columnIndex = 0;
    
        row.createCell(columnIndex++).setCellValue(item.getId());
        row.createCell(columnIndex++).setCellValue(item.getName());
        row.createCell(columnIndex++).setCellValue(item.getValue());
        // ...
    }
    
    workbook.write(someOutputStream); // Write the Excel result to some output.
    

    In order to offer this as a download to the JSF response, you need to provide the ExternalContext#getResponseOutputStream() as someOutputStream. You also need to set the response content type (so that the browser knows what application to associate with it) and the response content disposition (so that it’s opened as an attachment and that it has a valid filename).

    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext externalContext = context.getExternalContext();
    externalContext.responseReset(); 
    externalContext.setResponseContentType("application/vnd.ms-excel");
    externalContext.setResponseHeader("Content-Disposition", "attachment;filename=export.xls");
    workbook.write(externalContext.getResponseOutputStream());
    context.responseComplete(); // Prevent JSF from performing navigation.
    

    In the end, FacesContext#responseComplete() must be invoked to prevent JSF from performing the default navigation task (which would only corrupt the Excel file by appending some HTML output of the navigated page to the end).

    Note that the above JSF example assumes JSF 2.x. If you’re actually using JSF 1.x, which lacks several convenience ExternalContext delegate methods, then you’d need to grab the raw HttpServletResponse by ExternalContext#getResponse() and perform the actions on it. See also How to provide a file download from a JSF backing bean?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel table with some data that I would like to export
I would like to export some macros that I have defined and be able
I have a sictus prolog file (.pl-file) that I would like to export as
I have a spreadsheet, the contents of which I would like to include as
I have a Word document and would like to export the content including the
I would like to know how to export the contents of a table or
I would like to export a GridView to excel, which is easy enough. But
I would like to export a Java Bean or ResultSet(JDBC) into a CSV file
I'm using IIS6 using powershell I would like to export a specific virtual directory
We built a iphone app and now we would like to export it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.