Jasper Reports & addTableFilterParam

I’m just about to embark on the journey that is ‘Jasper Reporting’! Having watched the tutorial video I was surprised to see that when reports are built (I guess designed outside of Servoy with iDsign) we need full SQL and that is related directly to the database server using the same jdbc connectors.

So, if the reports are linked directly to the data servers rather than through Servoy, therefore I assume that the addTableFiletrParam has no effect on the form data?

Did I get that wrong?

That’s right, it’s like starting all over again, even need to define the relationships between your tables again… :cry:

Correct.
However by sending a parameter to the Jasper Report corresponding to your table filter the same effect can be obtained. Similarly, for a SAAS report - pass in the tenant/saas id as a parameter.

Jasper Reporting is a learning curve for sure and there are a few known “unknowns” - i.e. not in the [out of date] docs to be aware of or you will find them yourself! Avail yourself of the Jasper Forum when weirdness crops up.

Good reporting.

Thomas Parry:
Correct.
However by sending a parameter to the Jasper Report corresponding to your table filter the same effect can be obtained. Similarly, for a SAAS report - pass in the tenant/saas id as a parameter.

Do you mean pass this in for every table referenced Thomas? Its really the SaaS elements I’m most concerned about.

A lot of my tables are SaaS but some significant aspects are shared library tables too. having built the SaaS aspects into my app already I was hoping to NOT have to re-do it for reporting! Much of my reporting can actually be done in Servoy without Jasper - and moving toward Jasper was mainly becuase of the need for some graphs and charts. Seem’s like that’s difficult to do in Smart and Web Client using Servoy alone (beans not showing / printing in Web Client etc).

I saw Bob’s tutorial on the Google charts and thats really interesting but I already know some of my Clients will be working on-premisis and off-line, so google connection will not allways be possible. Adrian mentioned something about Easycharts being Smart and Web enabled now - so perhaps Servoy and Easycharts would be a better approach, retaining the SaaS already built and giving good charting too inside Servoy?

Do you mean pass this in for every table referenced Thomas? Its really the SaaS elements I’m most concerned about.

Usually there is only one saas parameter (i.e. the tenant) that applies to all tables. Other parameters can be passed in to the report to customize the desired result. (Such as the id of the customer which is then used in a relationship). Yes you have to build the SQL to define the relationships desired for that report. The iReport built in SQL designer helps a lot with that task. But I do agree it is like a duplication of effort since it is already done in Servoy.

Depending on the magnitude of the effort perhaps as you said using a charting add-on within Servoy is better for you.

Thomas Parry:

Do you mean pass this in for every table referenced Thomas? Its really the SaaS elements I’m most concerned about.

Usually there is only one saas parameter (i.e. the tenant) that applies to all tables. Other parameters can be passed in to the report to customize the desired result. (Such as the id of the customer which is then used in a relationship). Yes you have to build the SQL to define the relationships desired for that report. The iReport built in SQL designer helps a lot with that task. But I do agree it is like a duplication of effort since it is already done in Servoy.

Depending on the magnitude of the effort perhaps as you said using a charting add-on within Servoy is better for you.

Thanks for that feedback Thomas - I’m reviewing the options!

JasperReports has some inner abstraction mechanism that allow you to give him an object to use for filling the report.

If I were you I would look into the API of JasperReports: it is quite easy to create an object that implements the interface JRDataSource.
There’s only 2 methods that you need to implement into a wrapper object around a DataSet for exemple or maybe even a FoundSet.

You could create a plugin that creates the JRDataSource from a FoundSet and pass this to JasperReports to use, avoiding the need to duplicate the SQL…

I would doubt it is that difficult. If I can find the time, I will write it soon.

ptalbot:
JasperReports has some inner abstraction mechanism that allow you to give him an object to use for filling the report.

If I were you I would look into the API of JasperReports: it is quite easy to create an object that implements the interface JRDataSource.
There’s only 2 methods that you need to implement into a wrapper object around a DataSet for exemple or maybe even a FoundSet.

You could create a plugin that creates the JRDataSource from a FoundSet and pass this to JasperReports to use, avoiding the need to duplicate the SQL…

I would doubt it is that difficult. If I can find the time, I will write it soon.

Hi Patrick - thanks for that feedback - I’m afraid you just went around 6 steps beyond my skill level :shock: :oops: :D Still working at getting a grasp of what and how Servoy does things - and all things java / script etc!

My understanding of how the plugins are built and run is redimentary to say the least - and I was hoping to get away without any plugins at all actually (only to reduce potential error in my own handling of them) but that seems unlikely now.

Any support to make Jasper easier to deploy would be appreciated (and I know not just by me!).

Patrick:
I assume that your method means that in the Servoy app a result set corresponding to the data that is desired to be in a report has to be generated so that a Jasper reports data source is able to be used? Perhaps that task is not so easy? If it is then I agree that the design of a Jasper Report using a data source could be more efficient.

Looking forward to your “code”. Perhaps it could be an enhancement to the plugin of Servoy that specifies a data source (or I suppose a parameter passed in).

Cheers,
Tom

Tom:
It is a wild guess, but if I look at the Servoy 4.x Public API (I don’t know about the older one, never worked with Servoy 3.5.x), I see 2 interfaces IFoundSet and IDataSet which could potentially give me access to the client data created by a simple search.

In the IFoundSet interface methods, I see String getDataProviderNames(int type) and IRecord getRecords(int startrow, int count) that should, given a Foundset as parameter to the plugin, allow me to create an objet implementing the JRDataSource interface.

You need to understand that a JRDataSource is not required to be a ResultSet, it can be a anything that contains data : like a bean, an array, a csv dataSource, an Hibernate datasource, a tableModel datasource, an xml datasource, etc… all these implementations already exists ! @see the “All know implementing classes” of the JRDataSource interface.

So you could use a Foundset, get its data and create an inMemory DataSource and fill the report with it.

All of this is there “potentially”, if you look at the API. Of course I haven’t tested it yet, so there might be some tricky state problem, but I will give it a try, I promise. I will start to have a look at the implementation of the servoy-jasperreports-plugin since I understand it is open source on google-code, and see if I can plug that idea in. Will keep you informed…

Cheers,

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 :cry:) - 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 ;-)
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)

ptalbot:
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,

Did this go any further Patrick - any feedback from Servoy on the possibility of them including this in the official version?

Kahuna:
Did this go any further Patrick - any feedback from Servoy on the possibility of them including this in the official version?

Unfortunately, no!

I have no idea where/to whom submit my patches to, the google code site has no project owner’s email published!
Who is really responsible for this plugin??? Who is vetoing for code changes? Do you know?

Since I haven’t been contacted by anyone about this, I thought nobody cared, so I didn’t go any further… but I am still willing to, if there is an interest.

I repeat that my solution DOES work, and IMHO is much cleaner than having the server re-query the database again.
Anyway, I think that you should be able to choose from both approach depending on what you want to achieve…

ptalbot:

Kahuna:
Did this go any further Patrick - any feedback from Servoy on the possibility of them including this in the official version?

Unfortunately, no!

I have no idea where/to whom submit my patches to, the google code site has no project owner’s email published!
Who is really responsible for this plugin??? Who is vetoing for code changes? Do you know?

Since I haven’t been contacted by anyone about this, I thought nobody cared, so I didn’t go any further… but I am still willing to, if there is an interest.

I repeat that my solution DOES work, and IMHO is much cleaner than having the server re-query the database again.
Anyway, I think that you should be able to choose from both approach depending on what you want to achieve…

Posted a Request here: viewtopic.php?f=13&t=12409

Hope you don’t mind me referencing you Patrick?

Who knows???

Kahuna:
Hope you don’t mind me referencing you Patrick?

Who knows???

No problem! I just hope this will lead to something…
I would not like having to patch the plugin for each new release :wink:

Patrick,
you can submit a patch - I sent mine to Paul Bakker but I think you should try to contact Bogdan (?) He seems to be working on these plugin issues.

Mind you I would like to see evidence of some more testing…

No, I have not yet tried it. Maybe soon…

I am modifying the plugin myself to work around another issue of my own.

Later…

Hi Thomas,

is your issue still related to excel export? Don’t you think it is more related to the JasperViewer itself than the Servoy plugin?

Anyway, I have made the patch as follow, trying to be as unobstrusive as possible :

  • there’s only 2 method added to the IJasperReportsService interface, implemented in the JasperReportsServer class,
  • of course, to avoid making dumb copy of he methods I had to do a little bit of refactoring to make my new methods use the same code as the one using the dbalias String,
  • same thing for the JasperReportsProvider class, the patch is much bigger than expected because it didn’t recongize the code in the refactored method, but there isn’t much changed, really.

Being still unsure to whom I should submit this patch, you (and others) will find it attached here.

servoy_jasperreports.patch.zip (6.72 KB)

Hi all,

please ignore the precedent patch! I’m really sorry about this, it was running late, so I overlooked two lines of code, if you want to try patching the plugin yourself, use this one instead. I saw the problem this morning when testing with the sample solution I did previously.

Again, really sorry :(

Attached also an update version of the sample solution with the plugin compiled and jasper reports source, etc…

Thanks

jasperReportsFromAFoundSet.zip (79 KB)

servoy_jasperreports.patch.zip (6.87 KB)