Problem with parameters in custom datasource

By: Ricardo Trindade - rjst
Problem with parameters in custom datasource
2005-08-07 14:23
Hi,

I'm having a bit of a problem implementing a Custom DataSource, because I can't access the report parameters inside the Custom DataSource.

Since I create my datasource with a DatasourceProvider, I can access the report object, but I can't seem to find a way to get the filled parameters from it, so my datasource instance can be customized by the report parameters (like done when using SQL query).

So my question is, how can I access the filled parameters from a custom data source ?

thanks
Ricardo





By: Ricardo Trindade - rjst
RE: Problem with parameters in custom datasou
2005-08-09 06:37
Hi,

Can anyone from the core help here, please ?

thanks
Ricardo





By: Teodor Danciu - teodord
RE: Problem with parameters in custom datasou
2005-08-10 02:22

Hi,

It is the responsability of the parent application to
supply the data used by JasperReports.

In your case this is more obvious because you are
using a custom data source.

So, to put things in a different perspective for you:
your application supplies a map with parameter values
and a data source object when calling the filling method
of JasperReports.
You have both parameter values and data source in your
hands there. It is your application that creates them.
Why can't you just link them when you create your
custom data source object?
Why is it that the constructor of your custom data
source does not receive a map with those parameters?

This will not work only if you are relying on some
<defaultValueExpressions> for some of the parameters.

I hope this helps.
Teodor





By: Ricardo Trindade - rjst
RE: Problem with parameters in custom datasou
2005-08-10 03:31
Hi,

I understand the design. What you suggest works, but I have some issues with it. Part of the problem is that my application doesn't supply the map with objects, I create a custom data source based on a script (stored in the query property of the report), that gets the objects and responds to next() and getFieldValue().

I could, as you suggest, give the parameters to the DataSource constructor, but I'm using JRDataSourceProvider to create my datasource.

Since I do report development from IReport, if I stop using the JRDataSourceProvider, I won't be able to pass parameters to my datasource inside IReport. A possible solution would be to change JRDataSourceProvider to receive parameters, but it would still be a ugly solution because, as you said, <defaultValueExpressions> would never work for these parameters.

Another issue I have is that custom data sources have less configuration possibilities than sql queries. The report has a query tag, but not a general config section for other data sources. I tought about it a bit, and think that a script passed to a script-based DS is similar to a query passed to a connection-based DS, but support for the former is lacking from IReport (that's why I store my script in query-tag)

Hope this explains our use-case and motivation.

BTW, good product, been using it since the start!

thanks
Ricardo Trindade
2004 IR Help's picture
Joined: Aug 17 2006 - 3:49am
Last seen: 15 years 9 months ago

2 Answers:

Hi, is there any solution to this problem yet?

I am also implementing JRDataSourceProvider and JRDataSource, and I need to customize the JRDatasource using a parameter passed in from iReport. How and where can I get the parameter value that I pass in from iReport? Can I get it in JRDataSourceProvider implementation?

If I don't use iReport, I know I can use the JasperFillManager.fillReport and pass in a hashmap of parameter, and I can get the parameters from the parent application, but how to do this from iReport? Thanks, Arie



Post Edited by foyasing at 08/14/2009 07:38
foyasing's picture
Joined: Aug 12 2009 - 8:31pm
Last seen: 12 years 9 months ago

Hi,

 

There is no problem on this old thread whatsoever.

You are posting to a 4 year old thread which talks about things that are no longer relevant to the issue you encoutered.

 

In the last 4 years many new feature have been added to the JasperReports engine, including the query executers.

These are imlementations of the JRQueryExecuter interface that are able to create data source instances base on information coming from parameters and from the report template itself. You should check how to create your custom query executer by looking at the default implementations that come with the JR library itself.

A custom query executer is not forced to use a query to create a data source and could rely on report parameter values alone. However, in order to make use of a custom executer of your own, you have to register it with a query language that you define yourself. Check the default.jasperreports.properties fil in the JR jar to see how the default query executers are registered with the known query languages that JR supports by default.

 

I hope this helps.
Teodor

 



Post Edited by teodord at 08/14/2009 07:48
teodord's picture
23094
Joined: Jun 30 2006 - 9:00am
Last seen: 2 weeks 6 days ago
Feedback
randomness