Two DataSource in report

前端 未结 1 1868
说谎
说谎 2020-12-22 05:20

I have to make a report in jasperReports
I fill my initial report with a DataSource like this

File mainJasper = new File( servletContext.getRealPath(\"/         


        
相关标签:
1条回答
  • 2020-12-22 06:02

    You can send the second one as a parameter.

    parametros.put("dataSource2", List2 );

    In the report set the parameter type as

    net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

    You can use $P{dataSource2} as a datasource to a subreport, in a Table, in a List.

    Not sure if I understood correctly or it was a different matter,but if you want this to be the datasource of your subreport go to the subreport element on the main report add the following lines to set it:

    <subreport>
    ...
    <dataSourceExpression><![CDATA[$P{dataSource2}]]></dataSourceExpression>
    ...
    </subreport>
    

    If this was not what you wanted and you need more specific details, let us know what exactly you will use the second datasource for.

    An example - populate a table

    1.declare a subdatase (supposing 'code' and 'caption' are the fields of your objects in List2)

     <subDataset name="Table Dataset 1">
                <queryString language="SQL">
                    <![CDATA[]]>
                </queryString>
                <field name="code" class="java.lang.String"/>
                <field name="caption" class="java.lang.String"/>
            </subDataset>
    

    2.the actual table - set the subDataset to have the name of the one you declared("Table Dataset 1") and REPORT_DATA_SOURCE parameter to be the parameter which contains your List2 ("dataSource2")

    <jr:table ...>
        <datasetRun subDataset="Table Dataset 1">
            <datasetParameter name="REPORT_DATA_SOURCE">
                 <datasetParameterExpression><![CDATA[$P{dataSource2}]]></datasetParameterExpression>
            </datasetParameter>
        </datasetRun>
    .....
    </jr:table>  
    
    0 讨论(0)
提交回复
热议问题