Passing the List of primitive type objects as datasource for subreport

Perlos picture Perlos · Aug 14, 2012 · Viewed 36.3k times · Source

I need to pass to my subreport a dataSource with help of master report's List<String> parameter. I don't know what is a type of dataSource is correct and how to get value in subreport.

The snippet from my master report:

<parameter name="seznamPriloh" class="java.util.List" isForPrompting="false"/>
....
<subreport>
    <reportElement x="0" y="56" width="555" height="76"/>
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{seznamPriloh})]]></dataSourceExpression>
            <subreportExpression><![CDATA[cz.alis.keong.jasjdr.reporting.ReportCompiler.compile("R79_SeznamPriloh")]]></subreportExpression>
</subreport>

The snippet from my subreport:

<detail>
    <band height="23">
        <textField>
            <reportElement x="56" y="3" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{}]]></textFieldExpression>
        </textField>
    </band>
</detail>

Please advise me how to pass the datasource to subreport via master report's parameter of java.util.List<String> type.

Edit: 08.14 14:20 Add Tags to Java

Edit: 08.14 15:30 relates with How do I print a list of strings contained within another list in iReport? and works for 4.5.0 And List<String>

Answer

Diego Urenia picture Diego Urenia · Aug 14, 2012

You have to specify what field you're using in your sub report. You are passing $F{} and as you are passing a List<String> as a DataSource you should put $F{_THIS}. Of course you have to add a field with that name too, only doing that you can use the expression $F{somefield}.