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.

October 18, 2006 at 5:12 am
Hey C!
don’t care that much about client side state saving
You know the numbers…
but that component is def. nice!
-M
December 19, 2006 at 7:25 am
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.
November 14, 2007 at 11:12 am
Does not work when the number of columns inside a dataTable is dynamic??
November 19, 2007 at 12:27 pm
May 7, 2008 at 6:53 am
Need to implement Export to excel in our project in JSF, please help.
Thanks in advance.