Tuesday, April 21, 2015

Exporting Data from ADF Table

Exporting Data from ADF Table


In this post we shall look at how to export data from an ADF table.To export data from an ADF table we shall use an export collection action listener from the operations component panel of ADF Faces.

General steps which i followed to export data from ADF Table declaratively.

  • Inside a Layout container had a panel collection component
  • Under this layout container have a panel collection component used
  • Inside the panel collection dropped an read only ADF table
  • Now we can either use the toolbar facet or menu facet of panel collection component
  • In the current example have used toolbar facet have tried it with menu facet also the steps are the same.
  • Toolbar facet of panel collection drop a toolbar and drop a button into the toolbar, give the button an appropriate text
Inside the button drop an export collection action listener a dialog opens up asking for two mandatory attributes for this listener which are as mentioned below:

i) ExportedId - ID of the component to be exported
ii) type - export type. The only currently supported value is 'excelHTML'

Other optional parameters are
iii) filename - file name for the exported content
iv) title - the title of the worksheet of the exported content
v) exportedRows - rows to include in the exported content

specific reason to use panel collection is to wrap my collection component which is the table as it provides toolbar and menu facets

Note:
Only the following can be exported:

Value of value holder components (such as input and output components).

Value of selectItem components used in selelctOneChoice and selectOneListbox components (the value of selectItem components in other selection components are not exported).

Value of the text attribute of a command component.


Value of the shortDesc attribute on image and icon components.

Following is the sample code snippet of my demo app.

<af:panelStretchLayout id="psl1">
          <f:facet name="center">
            <af:panelCollection id="pc1">
              <f:facet name="menus"/>
              <f:facet name="toolbar">
                <af:toolbar id="t1">
                  <af:commandToolbarButton text="ExporttoExcel"
                                           id="ctb1">
                    <af:exportCollectionActionListener type="excelHTML"
                                                       exportedId="datatoexport"
                                                       filename="Employee"
                                                       title="EmployeeExport"/>
                  </af:commandToolbarButton>
                </af:toolbar>
              </f:facet>
              <f:facet name="statusbar"/>
              <af:table value="#{bindings.ExportEmp.collectionModel}" var="row"
                        rows="#{bindings.ExportEmp.rangeSize}"
                        emptyText="#{bindings.ExportEmp.viewable ? 'No data to display.' : 'Access Denied.'}"
                        fetchSize="#{bindings.ExportEmp.rangeSize}"
                        rowBandingInterval="0"
                        selectionListener="#{bindings.ExportEmp.collectionModel.makeCurrent}"

                        rowSelection="multiple" id="datatoexport">

This is how the application looks when it is run




Once you click the export excel button a dialog appears on whether to save the data




Saved excel file worksheet title has the title as given in the export collection action listener title property





Uploaded is the sample app here

References:

  1.  Export data from Tables,Trees
  2.  Export Collection Action Listener









1 comment:

  1. Hello, i think that i saw you visited my website thus i came to “return the favor”.I'm attempting to find things to improve my site!I suppose its ok to use some of your ideas!!conex for sale

    ReplyDelete