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.
Update(06 May 2009): For the ultimate JSF export datatable(excel, pdf, csv, xml) experience see PrimeFaces Exporter.