java ireport 子报表,在iReport中的列表中创建子报表

I have a list of goals, each of which have another arraylist in it. I want to have the details in the child arraylist to be displayed using a subreport. I would like to have a subreport for each of the objects in the child arraylist.

The issue I am facing is that, I can't seem to find a way to specify the arraylist as data source for the subreport. When trying to create datasource, I can't select fields of the dataset on which the list is built, only the fields of the main report can be selected.

Is it possible to do this in iReport.? I am stuck with this for quite some time now. Any help is appreciated. :)

解决方案

With information given this would be the answer.

Main bean (your goals?), containing List of other bean (SubBean).

public class Bean {

private String var1;

private List subBeans;

public String getVar1() {

return var1;

}

public void setVar1(String var1) {

this.var1 = var1;

}

public List getSubBeans() {

return subBeans;

}

public void setSubBeans(List subBean) {

this.subBeans = subBean;

}

}

Sub bean

public class SubBean {

private String var2;

public SubBean(String var2){

this.var2 = var2;

}

public String getVar2() {

return var2;

}

public void setVar2(String var2) {

this.var2 = var2;

}

}

How to pass the SubBean List to a subreport.

You need the field subBeans in you main report.

I suggest that you pass the location of the .jasper file as a parameter (Note jasper report needs absolute path) es. in main report

and in java pass it (in example sub folder "jasper" in working directory is the location of the subreport.jasper)

paramMap.put("SUBREPORT_DIR", new File("jasper").getAbsolutePath() + File.separator);

Now just call your subreport (needs to be complied into .jasper) from main report like this.

Hence:

I'm creating a new JRDataSource for the sub report passing the List of SubBean in the current Bean

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{subBeans})

indicating the absolute location of the compiled subreport.jasper

$P{SUBREPORT_DIR} + "subreport.jasper"

so now in your subreport you can use the field: var2 of the SubBean, just define it like this in the subreport.jrxml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值