일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- node.js
- 프라하
- vba
- react.js
- pyenv
- CSV
- 체코
- 방콕
- terraform
- 釜つる
- 미츠이 스미토모
- Selenium
- codebuild
- javascript
- 三井住友カード
- documentdb
- 아타미
- 熱海
- PayPay
- local
- PostgreSQL
- 뮌헨
- 메르페이
- JenkinsFile
- 페이페이
- Python
- duckdb
- 카마츠루
- 태국
- typescript
- Today
- Total
도쿄사는 외노자
Creating JasperReport with subreports using datasource 본문
출처 : http://junaedhalim.blogspot.jp/2009/12/creating-jasperreport-with-subreports.html
Creating JasperReport with
subreports using datasource
In my previous post, I explained how to use datasources to create jasper reports. As I promised, now I am going to explain how to use subreports with datasources.
The concept is very similar. All we have to do is pass the appropriate datasource(s) to the subreport(s).
For example, say we have the following reports in hand:
1. MasterReport.jrxml
2. SubReport1.jrxml
3. SubReport2.jrxml
Both the subreports are contained in the master report.
Now prepare the datasources for these reports (as list, as I mentioned in my previous post):
1. masterReportDataList
2. subReport1DataList
3. subReport2DataList
Construct 3 TestDataSource(extends JRDataSource) type objects using these 3 lists. Say these are:
1. masterReportDS
2. subReport1DS
3. subReport2DS
Now we have to pass these datasources to the appropriate reports.
I am going to pass the subreport datasources as parameters to the main report, while passing the master report datasource as usual - using the following call:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReportPath, parameters, masterReportDS);
In the parameter HashMap, we are going to put our subReport DataSources and any other parameters needed by the report.
Map parameters = new HashMap();
parameters.put('subreport_datasource',subReport1DS);
parameters.put('subreport_datasource_2',subReport2DS);
Now open the master report using iReport. Add two parameters to the main report named subreport_datasource and subreport_datasource_2. Set the data type of these two parameters as net.sf.jasperreports.engine.JRDataSource.
Open the properties window of subreport1. Set the following:
Connection type: Use a datasource expression
Data Source Expression: $P{subreport_datasource}
Do the same for the other subreport:
Connection type: Use a datasource expression
Data Source Expression: $P{subreport_datasource_2}
If you are not using iReport, then open the masterReport.jrxml in any text editor. Go to the subreport section (look for <subreport>). Remove <connectionexpression> tag (if any). Add the following:
That's all. Now you can create reports containing subreports using DataSources. You can even have one subreport inside another.
There is a beautiful article I found earlier on this topic. You can find that here.
Thanks for visiting. Good bye.
정리하자면...
SubReport에 데이터를 보낼 때엔
MainReport에 net.sf.jasperreports.engine.JRDataSource 클래스로 Parameter를 정해 두고,
Java쪽에서 데이터를 MainReport에 보낼 때
SubReport용 Data를 해당 Parameter명으로 동봉해서 보내야 한다는 거다.
그렇게 받아온 Patameter를 다음과 같이
Connection type: Use a datasource expression
Data Source Expression: $P{subreport_datasource}
해당 Parameter를 SubReport의 ReportData로 활용한다고 설정하면 된다.
'Tech > iReport' 카테고리의 다른 글
Error retrieving field value from bean (0) | 2015.12.16 |
---|---|
BigDecimal계산식의 Divide 오류 해결 (0) | 2015.12.11 |
NoSuchMethodException: Unknown property ' ' (0) | 2015.10.29 |
DB(PostgreSQL) 연결 (0) | 2015.10.22 |
SubReport에서의 무한루프 문제 (0) | 2015.10.20 |