How to transfer data to Subreports?

0

Hi,

When making a complex report, I had to break everything into subreports.
There are a couple of questions:

1. How to transfer datasource to subreport correctly? Found in the project in jrxml such an example:
((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource ("accounts")
There are no code examples. I must add "accounts" to the settings map, where will be, let's say List <AccountDto>? And how I can get this data in the subreport?

2. In 5 of 7 subreports a separate datasource is not needed, but it's needed to receive the fields of the main report. What is needed for this? Let's say id and name need to be printed on different pages in different blocks.

I have that code to link params to Master report:
Map<String, Object> map = objectMapper.convertValue(paramSettingDto, Map.class);
renderParameters.setDataModel(singletonList(map));
renderParameters.setFormat(format.getExtension());
renderParameters.setTemplateId(PARAM_SETTING_TEMPLATE_NAME);
renderParameters.setZip(false);
In params of Master report comes all fields of given paramSettingDto.

makushatnik's picture
Joined: Jan 21 2016 - 2:46pm
Last seen: 2 months 2 weeks ago

1 Answer:

0

Hi, I'm not familiar with JSON as DataSource... so that's why just the second part, how to transfer fields to the SubReport.

Therefore you can create so called "SubReportParameters" at the SubReport-Element in MainReport.

You must define a SubReportParameter let's say "SR_Name" and as Expression you link to the (current) field value ... e.g. $F{name}

In your SubReport you define now a new (normal) Report-Parameter with the same name (in our sample "SR_Name") so that you could now use this "normal" parameter as $P{SR_Name} in your SubQuery or whatever else.

hth + regards

C-Box

 

C-Box's picture
2250
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 week 3 days ago
Feedback