Defect #777
using the same foundset for 2 subreports doesn't work
100%
Description
using the same foundset for 2 subreports doesn't work. First report will get a foundset second will not. See sample files. Made with the database example_data orders.
Files
History
Updated by Sanneke Aleman over 11 years ago
- File orderdetails.jrxml orderdetails.jrxml added
- File orderdetails_2.jrxml orderdetails_2.jrxml added
- File orders.jrxml orders.jrxml added
Updated by Andrei Costache about 11 years ago
- Status changed from New to In Progress
- Assignee set to Andrei Costache
Hi Sanneke,
Have you tried the same scenario with the 4.x version of the plugin? What results do you get with that setup?
Regards,
Andrei
Updated by Andrei Costache about 11 years ago
Hi Sanneke,
Using Servoy 7.x and the 4.x (trunk) version of the plugin everything works just fine.
Still, we are trying to have a look at this using the 3.x version but there is a problem, apparently, with the report files (iReport 4.0 cannot open them, seems they have been created with a newer version of iReport). What version of iReport have you used when creating/editing them? In case you have used a version higher than the recommended 4.0 (for the 3.x plugin), could you please export with iReport 4.x as well?
Best regards,
Andrei
Updated by Sanneke Aleman about 11 years ago
I tested this with the 4 plugin and 7.3.1 We did update the plugin to jasper 5.5 but would that cause this problem?
Updated by Andrei Costache about 11 years ago
Sanneke Aleman wrote:
I tested this with the 4 plugin and 7.3.1 We did update the plugin to jasper 5.5 but would that cause this problem?
What results did you get by testing with plugin version 4.x?
Also, you say you update to jasper 5.5: which base plugin version did you use to update with jasper 5.5? Did you get the foundset problem after the update to the jasper engine?
Regards,
Andrei
Updated by Andrei Costache about 11 years ago
Just tried this with a simple 3.3.x and a Servoy 7.3.1 and both foundsets seem to get the data.
I suppose you are using a simple call to runreport, yes?
Updated by Sanneke Aleman about 11 years ago
- File orders.jrxml orders.jrxml added
- File orderdetails_2.jrxml orderdetails_2.jrxml added
- File orderdetails.jrxml orderdetails.jrxml added
To be sure I tried with the plugin 4.0.0 Jasper 4.6 servoy 7.3.1. But I don't get any data in the the second subreport.
Updated by Sanneke Aleman about 11 years ago
This is my call to the report:
plugins.jasperPluginRMI.runReport(foundset, 'orders.jrxml', null, plugins.jasperPluginRMI.OUTPUT_FORMAT.VIEW,null);
Updated by Andrei Costache about 11 years ago
Managed to see this and also find the cause: filling a subreport exhausts the data source passed to it. Therefore we need to "rewind" the datasource for the following subreport.
Looking into finding the best way to do this.
Updated by Andrei Costache about 11 years ago
- File orders.jrxml orders.jrxml added
- File orderdetails.jrxml orderdetails.jrxml added
- File orderdetails_2.jrxml orderdetails_2.jrxml added
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
Hi Sanneke,
As indicated, the exhausting of the datasource was the cause of the apparently empty foundset. The problem was the index of the foundset was at the "end", so no more "next()" data was available. This issue seems to be the way reports and subreports work with datasources, in Jasper Reports.
I have fixed the issue, in the 4.x version of the plugin. In a nutshell, I have added a helper method, to trigger/force the rewinding of the foundset, called com.servoy.plugins.jasperreports.JasperReportsResourceLoader.rewindServoyDataSource
. This method has to be called on the subreport foundset.
I am detailing the fix now:
- first, in orders.xml (main report), the orders_to_order_details
field has to declared of type com.servoy.plugins.jasperreports.AbstractServoyDataSource
- secondly, the second subreport has to be placed in a separate detail band; without this the datasource will not be rewinded
- thirdly, the datasource expression of the subreport must be wrapped inside the new method call; the new datasource expression needs to be this: <dataSourceExpression><![CDATA[com.servoy.plugins.jasperreports.JasperReportsResourceLoader.rewindServoyDataSource($F{orders_to_order_details})]]></dataSourceExpression>
What will happen is that when the second detail band is reached, the second subreport's datasource expression is evaluated and this will trigger a call to rewinding the foundset, this the second subreport will now have a "full" foundset to use.
I have added modified report files (please don't mind the coloring I added for fonts, it was just for testing purposes). Please have a look at these. The modifications are done mainly in the main report.
This was the easiest fix possible currently. We could have also tried to use Scriptlets, but this would be not very easy for unexperienced users of the plugin. The fix is inspired from what the creators of JasperReports offer as advice: http://community.jaspersoft.com/questions/514992/no-data-all-first-subreport.
Let me know if this works fine or if you encounter any problems.
Best regards,
Andrei
P.S. (Update) Please note that the orders_to_orders_details
field is of type com.servoy.plugins.jasperreports.AbstractServoyDataSource
, but should also work for other datasources which implement net.sf.jasperreports.engine.JRRewindableDataSource
(if all imports are done correctly in the report, so the compilation will succeed). For current Servoy datasources, using the AbstractServoyDataSource
will suffice.