Sunday, December 9, 2012

Exporting Data to Excel in ADF


Its a very common requirement to have download functionality for the data shown on UI . In ADF there might be requirement of downloading the search result data to an excel sheet.

ADF provides exportCollectionActionListener that does this job seamlessly with result table.

Here are the simple steps to achieve this :

1. Create View for the search functionality.
Like Employee -> Dept -> jobs data

Create the search criteria using the View criteria.

2. Create table with Query panel and result.

3. For alignment you can have this enclosed in panel stretch layout.

4. Drop a menuBar just above the result table.
Add a menuItem and then the exportCollectionActionListener , the code looks like this :

exportCollectionActionListener
FileName : Name for the excel sheet
Title : Title for excel tab
exportedId : Id of the result table of the VO like : resId1


 <af:menuBar id="mb1">
               <af:menu text="Download Data" id="m2">
                   <af:commandMenuItem text="DownloadToExcel" id="cmi1">
                          <af:exportCollectionActionListener exportedId="resId1"
                                                             type="excelHTML"
                                                             filename="SearchDataExcel"
                                                             title="Data"/>
                   </af:commandMenuItem>
               </af:menu>
 </af:menuBar>


5. Set partialTriggers property for the commandMenuItem as the Query component used for querying the data.This is to refresh the data that need to be exported.
 partialTriggers="qryId1"

6. Can also set the disable property of commandMenuItem to disable when no data is returned from the query.Like : disabled="#{bindings.EmployeeVO.estimatedRowCount&lt;1}

This will appear as below in UI.




This works great
Cheers!!

No comments:

Post a Comment