Jump to content
We've recently updated our Privacy Statement, available here ×

Passing Subreport Parameters


prinsesajade

Recommended Posts

hi! can anyone help me with this or any idea?

i have a main report with 3 subreports (Product, Agency1, Agency2)..this is how it works..

my first subreport (Product) have these fields Agency1Count and Agency2Count..the values of these fields will be dependent on the number of records processed in my other subreports(Agency1 and Agency2)..so if Agency1 has 12 records and 10 for Agency2 my Product subreport should display 12 for Agency1Count and 10 for Agency2Count..and here comes my problem..i don't know how i can pass these values from one subreport to another..

do u have any idea?please let  me know...thanks in advance..

 

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

i have just found the answer to my problem..i only have to add the same parameter (including the name) in my main report..say i have this parameter RATE in my subreport which is a map i just have to add the same paramter in my main report and in Subreport-->Properties-->Subreport Parameters..

 

Link to comment
Share on other sites

Did the method you described above actually work?

For some reason, I am also unable to pass subreport parameters... these are actually "Fields" in the subreport... does that make a difference?

But my problem could also be that the subreports are somehow "hidden" and just appear blank... does anybody know how I could solve this issue?

Thank you all in advance for your hints!

Link to comment
Share on other sites

yes it worked for me..

ur problem is the fields of ur subreport r blank?

this is how i make a subreport..

i put the datasource and path of  my subreport in a map..(see code below)

 

then in ur master report create a parameter with name the same as the key u used for putting the path/datasource in the map..

ex. SUBREPORT_DIR -- classType = java.lang.String

       SUBREPORTDATASOURCE -- net.sf.jasperreports.engine.JRDataSource

then in subreport properties in subreport expression put the variable u used for the path of ur subreport and in the connection expression put the variable u used for the datasource..

this is the best way i can explain this..hope this helps..

 

 


       

Code:
Map<String, Object> params = new HashMap<String, Object>();params.put("SUBREPORT_DIR", urreportpathhere);params.put("SUBREPORTDATASOURCE", urdatasourcehere);JasperPrint print =JasperUtil.fillReport(mainreportpath, params, mainreportdatasource);
Link to comment
Share on other sites

Thank you for your quick reply!

Both my mainReport datasource and my subReport datasource are created through a common list of dataBeans... perhaps that's my mistake?

Do the two dataSources need to be separate?

I'll give it a try...

Thanks again!

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

hello..this is pretty older post but i am hopeful to get some clue from here. I am having same scenario. one main report and 2 subreports (DataDetails and ProcessDetails.) Main report and DataDetails use jdbc connection while ProcessDetails must use JRDataSource. I am having problem while executing this within java file. I tried in following way.
1. created a java bean for the ProcessDetails(sub report which uses JRDataSource) and in the class file called its instance.
2. Main report file and DataDetails(both uses database connection) already exist. Didn't change anything in that.
3. In ProcessDetails subreport, connection type is kept to "Use a DataSource expression" and Data Source Expression is set to $F{newBeanField}(This is defined in java bean file).
4. in main class I did following,  please see the code.

5. Now my problem is as main report and DataDetials(subreport1) are connection oriented and ProcessDetails uses JRDataSource, I am not able to fill the report using either JasperPrint print = JasperFillManager.fillReport(fileName, jasperParameter, jbs); or JasperPrint print = JasperFillManager.fillReport(fileName, jasperParameter, conn);

6. Am i committing mistake anywhere? I know we can't use both connection and jrdatasource in fillreport. What I should change in order to generate every report. Please suggest/help/advise. Thank you in advance.

Code:
ArrayList<JasperBeanSample> list = new ArrayList<JasperBeanSample>();   JasperBeanSample jasperBeanSample1 = new JasperBeanSample();   jasperBeanSample1.setId(10);   jasperBeanSample1.setName("abcabc");   jasperBeanSample1.setEmailId("abc@gmail.com");   list.add(jasperBeanSample1);   JasperBeanSample jasperBeanSample2 = new JasperBeanSample();   jasperBeanSample2.setId(20);   jasperBeanSample2.setName("xyzxyz");   jasperBeanSample2.setEmailId("xyz@yahoo.com");   list.add(jasperBeanSample2);   JasperBeanSample jasperBeanSample3 = new JasperBeanSample();   jasperBeanSample3.setId(30);   jasperBeanSample3.setName("pqrpqr");   jasperBeanSample3.setEmailId("pqr@hotmail.com");   list.add(jasperBeanSample3);   JRBeanCollectionDataSource jbs = new JRBeanCollectionDataSource(list);   //jasperBeanSample1.setNewBeanField(jbs);   Map<String, Object> jasperParameter = new HashMap<String,Object>();   jasperParameter.put("newBeanParameter", list);      JasperPrint print = JasperFillManager.fillReport(fileName, jasperParameter, jbs);   //JasperPrint print = JasperFillManager.fillReport(fileName, jasperParameter, conn);
Link to comment
Share on other sites

  • 5 weeks later...

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...