foyasing Posted August 14, 2009 Share Posted August 14, 2009 HiI 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.ThanksCode: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 More sharing options...
teodord Posted August 14, 2009 Share Posted August 14, 2009 Hi, First, why did you implement this interface? How do you want to use it? Thank you,Teodor Link to comment Share on other sites More sharing options...
foyasing Posted August 14, 2009 Author Share Posted August 14, 2009 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 classThanks for your prompt response. Arie Code: Post Edited by foyasing at 08/14/2009 07:54Post Edited by foyasing at 08/14/2009 07:55 Link to comment Share on other sites More sharing options...
teodord Posted August 14, 2009 Share Posted August 14, 2009 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 More sharing options...
foyasing Posted August 17, 2009 Author Share Posted August 17, 2009 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.FieldsProviderThanks anyway.Post Edited by foyasing at 08/17/2009 06:48Post Edited by foyasing at 08/17/2009 09:00 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now