In the previous parts (Part 1 Part 2 Part 3 Part 4) we covered plain export, styling your exports and doing selective exports. Today I want to show you how to create more advanced and flexible way to get your data using a java object that we use for the export.
We start by creating 2 java classes one for the export and one of the Export Data
Then in each class add implements Serializable and the private variable on the row below. This is so the java VM can swap the data out disk if needed.
We will start by creating our data class, very simple. Check what type of data you want to export in each column, in my case I want to export
And then we use the generate setters/getters function in DDE by right clicking in the source window
And select all variables you want to autogenerate setter and getters for an click on OK
Time to create the getData function in the Export class the important thing here is that we return a a java object of the type List.
I also create the function as static because I will only run this function and return the data once. This is the code for the export class. The important thing to point out is
The I create the Exportdata object on each row and store it in the RowData variable
And when I have populated it I add it to the Data ArrayList Object the is returned from the function at the end.
In my Excel export component in All properties datarowexport and I select to create a wgpoi:ListObjectDataSource.
And click on the buildValues property to add some source
And we add this simple code to get the data from the Java objects returned you can expand you getData class and sending in filter parameters from the XPage as we did in Part 4 of this series but in this case the filtering will be done in java.
But wait, you might say how do we populate the column data. That’s the great part of the implementation. You write the name of you variable in you data class and the getter will do the rest. so in this case it will call getName from your row class that is returned.
With this new way of exporting you can combine the data from different sources not only one as I’ve shown in the past parts of this series of posts and giving even better exports to you users.
Integrating a better export into your application will make your users happier