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

How to transfer data to Subreports?


makushatnik

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

 

Link to comment
Share on other sites

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