Cagatay Civici’s Weblog

“Real power can’t be given, it must be taken”

Export JSF Datatable to Excel

Posted by cagataycivici on October 17, 2006

Lately I’ve committed a new component to the MyFaces Sandbox. It’s called ExcelExport and used to export the contents of a datatable as a regular excel file using Apache POI. The component must have a child that has onclick attribute, following is an example using a command button.

<s:excelExport for=”tableIdHere”>
    <h:commandButton value=”Export” />
</s:excelExport>

Also the example in myfaces repo:
http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/excelExport.jsp

For now it only works with server side state saving, using ajax and sending the view with the ajax request I’ll make the component start working with the client side state saving too. In my old project I’ve embedded this feature to the datatable itself by placing an excel icon on the top-right corner. The screenshots of my old work is here. The one I’ve added to myfaces sandbox is more flexible since it can be used with different types of child components, actually the idea behind the scenes is same but the usage is different.

5 Responses to “Export JSF Datatable to Excel”

  1. Matthias Wessendorf Says:

    Hey C!

    don’t care that much about client side state saving :) You know the numbers…

    but that component is def. nice!

    -M

  2. lingoosoft Says:

    Hi!

    I think I found a bug of s:excelExport.

    In my jsf page, used two dataTable with “rendered” attribute and only one dataTable could display at the same time.

    The two dataTable with the same value of “id” attribute.

    When the first dataTable displayed, the s:excelExport worked well; but the second displayed, the s:excelExport caused the exception.

  3. Anonymous Says:

    Does not work when the number of columns inside a dataTable is dynamic??

  4. Anonymous Says:

  5. Anonymous Says:

    Need to implement Export to excel in our project in JSF, please help.

    Thanks in advance.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>