I did a checkout of the svn sourced of the “servoy-jasperreports-plugin” from code.google.com.
I modified 3 classes quickly (not too much refactoring, a few quick copy and paste), to make it accept a javax.swing.table.TableModel as a first parameter instead of the server name (note that you can still use the server name if you want, though).
I only modified the interface (IJasperReportsService), the server implementation (JasperReportsServer) and the Client Plugin Provider (JasperReportsProvider) - the fun of it is that I did the plugin from inside Servoy (after all, it is an Eclipse distribution, and as such, quite capable of working on Java projects
) - That’s what I like best about Serclipse, you can work on Java projects too!
I also had to wrote a SerializableTableModel wrapper of the TableModel used by Servoy (which wasn’t the case
) - to avoid the java.io.NotSerializableException I encountered in Smart and Web Client when the model was send to the server from the client plugin. It works fine now, in web client too
.
So, you will find attached a little (working) example.
The archive contains my version of the “servoy-jasperreports-plugin” (complete with the sources modified)
- a sample report (based on the udm sample database)
- a sample solution (based on the udm sample database too)
You will have to replace your “servoy-jasperreports-plugin” (jar and jnlp) with this version (backup your “regular” plugin before of course)
Put the “reportFromServoyModel.jasper” (and optionnaly “reportFromServoyModel.jrxml”) in the folder you use on your server to put the jasper reports files (as declared on the Servoy Server Plugin Settings page under “jasperPluginRMI” with the key “directory.jasper.report”).
And finally import the solution (make sure you have the udm database source).
In short, I decided to use the TableModel because there is a JRTableModelSource already included in JasperReports, it saved me from the hassle of creating a new one, I am that lazy ![Wink ;-)]()
But you know that it is very easy to get a TableModel from a foundset (or a dataset) - see the code of the launchTest() function in the solution attached if in doubt.
The only drawback I would find with this approach is that you build a TableModel on the client and send it back to the server, so it could eat some bandwidth on big models and some memory on the client too.
But you can use it with relation also, filtering the foundset with databaseManager.convertToDataSet(foundset, [array of fields]) - again see the method.
The big advantage, too, is that you don’t need to hit the database again on the server, and you don’t need to rebuild manually all the SQL… In iReport though, if you want to work confortably, you will have to add a source, but it is possible to add fields manually without a query, just make sure, if you use relations to qualify the fields with the relation name (like “contacts_to_companies.company_name” in the sample case - open the sample report with iReport to see what I mean - I used 3.0.0 to be consistent with the version of jasperReports shipped with the plugin)
Give it a try, you will like it. If I find some time later, I will clean-up my code and submit a patch to the “servoy-jasperreports-plugin” development team (if they want it).
Cheers,
jasperReportsFromAFoundSet.zip (80.7 KB)