Jump to content
Changes to the Jaspersoft community edition download ×

How to get parameter value passed in from iReport


foyasing

Recommended Posts

 Hi

I implements JRDataSourceProvider interface.
In method  create(JasperReport report), I managed to get the custom parameter which i created in iReport.
I attach the code for create method.

But how do I retrieve the value for this parameter?
Please help.

Thanks

Code:
public JRDataSource create(JasperReport report) throws JRException {        TestDataSource ds = null;        try {            JRParameter[] parameters = report.getParameters();            JRParameter param = null;            // I skip the 16 built-in parameters            if(parameters.length > 16){                for(int i=16; i<parameters.length; i++){                    param = parameters[i];                    ds = new TestDataSource(db.getValues(param.getName(), "680"));                }            }else{                ds = new TestDataSource(db.getValues("userid", ""));            }        } catch (Exception ex) {            ex.printStackTrace();        }        return ds;    }
Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 Hi Teodor,

I need to create a java class with dynamic fields in it for JasperReport to reference and extract for reporting purposes as oppose to the conventional feature when it draws fields from a database table.

 

So, my implementation of JRDataSourceProvider will get a Resultset from data access layer (JDBC) and this resultset can be from any table with different fields.

 

The data structure that I pass from my data access layer is a collection of hashmap. The hashmap is a collection of fieldname and value of each record.

 

 

If I dont use iReport, I know I can do the following:

 

HashMap hm = new HashMap();
hm.put(parameter, paramValue);
JRMapCollectionDataSource mapCollection = new JRMapCollectionDataSource(xxx);
JasperPrint print = JasperFillManager.fillReport(fileName, hm, mapCollection);

 

Problem is: I need to use iReport.

I attach my full impementation of JRDataSourceProvider class

Thanks for your prompt response.

 

Arie

 

 

Code:



Post Edited by foyasing at 08/14/2009 07:54



Post Edited by foyasing at 08/14/2009 07:55
Link to comment
Share on other sites

Hi,

 

You need to implement a custom query executer that would create a data source instance base on some report parameter values or some other properties in the report template.

I have explained that to you on the other thread. Double posting is not encouraged.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

Hi Teodor,

Sorry for the double posts. Thanks for the input, I can now get the parameter value sent from iReport after implementing the JRQueryExecuter.

I've got another issue, how can I get the fields from this custom query?
Previously, I can do that by implementing JRDataSourceProvider.getFields().
Is this facility provided in the Query Executer?

Thanks a lot.

 

NOTE: Nevermind about the above question, I found the interface to implement for this function.
It's in com.jaspersoft.ireport.designer.FieldsProvider
Thanks anyway.


Post Edited by foyasing at 08/17/2009 06:48



Post Edited by foyasing at 08/17/2009 09:00
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...