03. Export a ListObjectDataSource to Excel


How to export a ListObjectDataSource to excel with POI4XPAGES
1. Download POI4Xpages
2. Install the Extension on your Server and Designer Client
3. Configure the Excel export
This time we are going to use a List of Objects to export to Excel.

In this example we created a Java class 'Contact' which contains the attributes of the Contact like 'FirstName', 'LastName', 'City', etc with the related getter and setter methods for these fields.

We also created a method to get all Contacts as an ArrayList in a class defined in the WebContent\WEB-INF\faces-config.xml as a managed bean, so we can access the data within the export function.

After the configuration of the excel file is done, we can proceed to export our ListObjectDataSource which we are going to define in the ‘exportDefinition’



We can choose between data2rowexport and data2columnexport which represents the export direction.
· startRow: 0 based. Defines the row where the export should start
· stepSize: 1 or higher. It’s possible to export a dataset to 1, 2 or more rows. (see columns for how to assign another row)
Assign the dataSource:


· buildValues: add a List of Objects. In this Case we call the method 'getAllContacts()' from our ContactBean which returns all Contacts as an ArrayList.
· values - this parameter can be ignored as it is not in use anymore.
Assign the columns:



Each column needs a columnDefinition.
· columnNumber: the number of the column (0 based)
· columnTitle: the name of the field in the dataSource (it will be invoked with “get<columnTitle>” on the object in the list)
· rowShift: this defines how many rows down the value should be shifted (multiple row export per dataset)

The export works with the same button we created for the Configuration export.