We are porting an existing Wicket application on Google App Engine. This application uses Wicket, Spring and Hibernate. If you read will it play in app engine, you will notice that Wicket is semi compatible and it does work with workarounds. Hibernate on the other hand is incompatible and Spring is fully supported. We began porting this application after changing persistence to use JPA instead of hibernate. We used workarounds for wicket described here.
This application generates Excel sheets and used Apache POI for generating Excel reports. Apache POI is not supported in Google App engine and it seems that Apache POI will not change their implementation to make it work for Google App Engine in near future.
We started looking at ways to generate Excel sheets. We decided on using java Excel API for our application. Let’s see how can we generate excel files for a Wicket application on Google App engine.
First of all add the maven dependency for JExcel in the application:
Start by mounting the shared resource in wicket Application class in its init() method. Suppose we have an EhourWebApplication class then its init() method will look like this:
ExportReportExcel class extends DynamicWebResource class and specifically overrides the getResourceState() and setHeaders(). The code listing for ExportReportExcel:
ExcelResourceState is an inner class extending ResourceState. If you look closely this ResourceState class overrides methods like getContentType(), getData(), getLength() and lastModifiedTime(). The getExcelData() method in this class will use the JExcel Api’s to generate Excel sheet. The code listing for the getExcelData() method using JExcel Api’s is given below.
Let us suppose we have a form ExcelReportForm and we want to generate the Excel report on its submit event. Then we can use the mounted URL to set the request target. The code snippet for the form and its submit method .
That is all that is required to generate Excel sheets in a Wicket application.
JExcel API’s do have some limitations as well. It does not generate or chart, graph or macro information. This information is however preserved when spreadsheets are copied. When adding images to a sheet, only PNG image formats are supported. JExcel was a right choice for our application, we had to change a small set of files in our application to use JExcel API’s instead of Apache POI API’s. We found an implementation of generating Excel files on Google Web Toolkit you can have a look here.