Difference b/w using Parameters and Fields as Report JR Data Source

0

Hi,

I am new on JasperReports and I want to learn, what is the main difference when filling the report data by JRBeanCollectionDataSource with Parameters or Fields.

I have a big report which has 10 tables in it. I pass the table datasources as parameters to the report. Should I pass the data to the fields, or passing data to params is just OK?

Thank you for your answers.

dytenstan's picture
Joined: Mar 8 2019 - 11:59pm
Last seen: 4 months 3 weeks ago

5 Answers:

1

Perhaps my two cents yet:

If you define a complex (nested) java-pojo/bean structure and use the JRBeanCollectionDataSource for your MainReportDataSet at calling the FillManager, so you don't know at this toplevel for what (nested) pojo/bean which substructure existst to pass all possible SubDataSources as parameters from outside!

So using a Field for a SubReportDataSourceExpression is also a good solution in this case - so a simple pojo/bean holding a substructure of childs within a ArrayList<SomeBean>  myChilds = new ArrayList<SomeBean>() could easily transformed to a new JRBeanCollectionDataSource to use in a List or SubReport Element as DataSourceExpression:  new JRBeanCollectionDataSource($F{MyChilds}

hth + regards

C-Box

C-Box's picture
2157
Joined: Jul 19 2006 - 5:58pm
Last seen: 2 days 16 hours ago
0

Neither. Data to a table should be passed as a subDataset

hozawa's picture
52592
Joined: Apr 24 2010 - 4:31pm
Last seen: 5 months 1 week ago
0

Hi Hozawa,

Ok, but how to fill that dataSet? I mean, I can pass the data to dataSet as parameter, than I can pass it to dataSourceExpression of dataSet as below;

<parameter name="list1" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>

<datasetRun subDataset="dsList1" uuid="bcc71b8c-7287-427c-a26e-20c49c38c30a">
    <dataSourceExpression><![CDATA[$P{list1}]]></dataSourceExpression>
</datasetRun>

Is that a wrong approach? Should I feed the dataSource with Field instead of Parameter?

Thank you.

dytenstan's picture
Joined: Mar 8 2019 - 11:59pm
Last seen: 4 months 3 weeks ago
0

In this case, it would be OK with using the value of a Parameter as a data source.
Does it cause an issue?

 

rpeguet's picture
6942
Joined: Mar 8 2011 - 2:06am
Last seen: 1 month 1 day ago
1

You should be using a parameter here, Fields are objects coming from the data source, Paramters are objects defined before the report query is executed and their value is an expression or custom input. In this case Parameter makes most sense

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 4 days 5 hours ago
Feedback
randomness