Passing main parameter to sub-datasets in JasperStudio

只愿长相守 提交于 2019-12-06 11:03:15

问题


i'm created a report with JasperStudio 5.5 that have many parameter defined in the main and a lot of sub-dataset (defined with tables) that required this parameters.

The situation:

/main/Parameters: myPar

/main/mySubDataSet1/
/main/mySubDataSet2/
...
/main/mySubDataSetN/

The sub-dataset need to use this parameter in her query: select * from Tab t where t.attr = $P!{myPar}

So, my problem is that the sub-dataset can't access at this main paramenter, all the time that i try compiled, the program send me "Parameter not found : myPar".

How i can do for use myPar in the sub-dataset?

p.s.: i read this thread Pass main dataset parameter to subdataset query (based on iReport) but without success...


回答1:


Well, you need to fill subDataset parameters with values where you actually make use of them. In this case the table which lists items from your subDataset needs to declare the necessary parameters and assign the values of the report-level dataset parameters to them.

In jrxml it sounds:

<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
    <datasetRun subDataset="mySubDataSet1" uuid="bbe7937c-a8f1-4838-811a-3f11ec1f8e35">
        <datasetParameter name="myPar">
            <datasetParameterExpression><![CDATA[$P{myPar}]]></datasetParameterExpression>
        </datasetParameter>
        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
    </datasetRun>
    ...
</jr:table>



回答2:


For detail:

<subDataset name="dsLines" uuid="a47307ff-90a8-476f-afd1-0fd8aa0517d0">
<parameter name="formalId" class="java.lang.String"/>
<queryString language="SQL">
    <![CDATA[
        SELECT s.formalid, sl.*
        FROM salesorder s INNER JOIN salesorderline sl
        ON (s.id = sl.salesorder_id)
        WHERE s.formalid = $P{formalId}
    ]]>
</queryString>
<field name="qty" class="java.math.BigDecimal"/>
...

<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="dsLines" uuid="3ef5ec78-ab18-4f44-88e6-f99f3eafac07">
<datasetParameter name="formalId">
    <datasetParameterExpression><![CDATA[$F{formalid}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="29" uuid="f675a273-7ea6-4bd4-8a55-c7522dfea2a8">
    ...



来源:https://stackoverflow.com/questions/21241303/passing-main-parameter-to-sub-datasets-in-jasperstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!