List<Object> as a JRBeanCollectionDataSource

2019-07-27 15:27发布

I'm passing a List as a JRBeanCollectionDataSource to a Subreport. Here Object is of Type A and B. The object type A has two properties: name and address and the object type B has the location property.

If Object is of type A then I have to display name and address in subreport. And if it is of type B then I have to display location in subreport.

I have to access a type of Object in a subreport, means is of which type (A or B)?. I have tried a lot but not found any solution.

Can anyone help me please. Thanks in advance.

1条回答
在下西门庆
2楼-- · 2019-07-27 16:22

You have many options:

First: Put a flag field in both objects stating is this Object A or Object B.
Then in Subreport Expression use a ternary statement like this:

objectType=="ObjectA"?"subreportA.jasper":"subreportB.jasper"

Second: Pass the sub report name as a field inside the object itself.
Then in Subreport Expression use the field like:

$F{subReportName}

Third: Make two subreports each is populated by its own type. If you want to show "Subreport A" then populate ObjectA and leave ObjectB list as null. In Jasper, if the populating list is NULL, the subreport is not rendered.

查看更多
登录 后发表回答