views:

305

answers:

1

am passing a List as a JRBeanCollectionDataSource to a Subreport. here Object is of Type A and B. A is having properties 'name' and 'address' and B is having property 'location'. if Object is of type A then i have display 'name' and 'address' in subreport. and if is of type B then i have to diaplay '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.

A: 

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.

medopal