Passing Parameter to a Subdataset?

For roughly the past week, I have been trying to pass a parameter from my main report to a subdataset for use in a bar chart via a dataset run.  The examples provided in "The Definitive Guide to iReport" are extremely basic and provide little in the way of specific configurations of a dataset run.

I was wondering if anyone here could provide a quick step-by-step explanation of how to pass a parameter to a chart/subdataset via a data set run?

I am using iReport 3.1.2.  I can provide my XML code and any additional details if they would be of any help.

 

Thank you very much in advance.  This problem has been a real nightmare.

gconsultant's picture
Joined: Nov 18 2008 - 9:00am
Last seen: 14 years 10 months ago

7 Answers:

First go to your subdataset and create the parameter and set the default value to be the main report's parameter. Now go to your chart properties > chart data > dataset run  and create the parameter and set the default value to be the subdataset's parameter.

kchaudhry's picture
4384
Joined: Apr 9 2007 - 6:10am
Last seen: 16 years 5 months ago

Thank you for the response - I actually just solved my issue also.

There appears to be a bug in iReport when adding a chart subdataset run parameter with the GUI. When the parameter is added (and the corresponding dataset parameters have been established), the following error is reported:

 

"Class not set for dataset [dataset name] parameter expression: [parameter name]."

This error occurs regardless of parameter map settings or connection/datasource settings. I was able to circumvent the error by adding the parameter in the XML view. Is there a way to forward this error to the developers for correction in a future update?  Thanks!



Post Edited by Grant Dole at 01/27/09 21:16
gconsultant's picture
Joined: Nov 18 2008 - 9:00am
Last seen: 14 years 10 months ago

plzz tel me what changes have u made in the XML.because i m facing the same problem

mpgm's picture
61
Joined: Dec 27 2008 - 12:37am
Last seen: 14 years 9 months ago

I was able to make the change by adding the dataset run via the xml view.  Trying to make any changes to the chart's dataset run via the GUI caused it to break again.  It will probably work if you do it with the GUI, then go into the xml, change something, change it back, and save it.  Just don't try doing any other edits to the chart dataset selection with the iReport GUI interface.

Here is an xml snippet (which was generated originally by the GUI):

 

Code:
<dataset>
	<datasetRun subDataset="Subset - Revenue">
		<parametersMapExpression>
			<![CDATA[$P{REPORT_PARAMETERS_MAP}]]>
		</parametersMapExpression>
 
<datasetParameter name="ChartID">
<datasetParameterExpression>
![CDATA[$F{IDDefinition_IDNumber}]]>
</datasetParameterExpression>
</datasetParameter>
 
<connectionExpression>
<![CDATA[$P{REPORT_CONNECTION}]]>
</connectionExpression>
</datasetRun>
</dataset></td></tr></tbody></table>
gconsultant's picture
Joined: Nov 18 2008 - 9:00am
Last seen: 14 years 10 months ago

Very useful your answer, I'm grateful. Bye bye.

jluiscruz027 - 10 years 8 months ago

I ran into that problem too ( 2 years after gconsultant had the problem)

with a <jr:table> which is bound to a subDataset.

Look at the bugtracker id 1227, it is a well known issue:

My Solution that works in iReport:

To <connectionExpression> in the <datasetRun> I added the report parameter map

in the XML-View by hand and that solved my problem

Code:
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components <a target="_blank" href="http://jasperreports.sourceforge.net/xsd/components.xsd">"><a href="http://jasperreports.sourceforge.net/xsd/components.xsd">" target="_blank">http://jasperreports.sourceforge.net/xsd/components.xsd"></a></a>
<datasetRun subDataset="my_info">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun> ...



Post Edited by photonflux at 08/03/2011 10:13



Post Edited by photonflux at 08/03/2011 13:03
photonflux's picture
Joined: Jul 19 2011 - 4:10am
Last seen: 6 years 3 weeks ago

On the topic of the bug in generating the xml....

I am trying to use a sub dataset for a chart but my source is a CSV file.  Is it possible to do this and how would I manually change the code?

 

cherieh's picture
48
Joined: Nov 4 2010 - 12:11pm
Last seen: 9 years 1 month ago

For the subdataset that you use in the chart you have to "duplicate" the variables from the main report.

In the report designer choose the subdataset and add variable

with the same name as in the main report if you like.

But the DefaultValueExpression of the subdataset variable must point to the value of the "main variable":

$P{main_variable}

 

It is possible that a chart will work with no further manual manipulations at the xml.

If not

repeat the parametersMapExpression in the subdataSet

in the xml View  as described above.

photonflux's picture
Joined: Jul 19 2011 - 4:10am
Last seen: 6 years 3 weeks ago
Feedback