Return value from subdataset in iReport

南楼画角 提交于 2020-04-11 17:04:33

问题


I know that it is possible to get a return value from a subreport to the main report in iReport. Also there are subdatasets which can also have an own SQL query like a subreport. As I understand a subdataset can only be used with list, charts etc., but I don't know how to access the subdataset fields, variables and parameters in the main dataset/report.

Is it also possible to get a return value from a subdataset? If not, how is it possible to access values from the subdataset?


回答1:


It is currently not possible to use a subdataset query in the main report structure. Your best option would be to use a table element, possibly only outputting one field to accomplish what you want to do.

Otherwise you would need to restructure your query to accommodate your needs to have data in the main report.




回答2:


in properties > Subreport properties > parameters > add > click icon near "value expression" then add your parameters or fields. and go to subreport for add parameter same name in report inspecter tab > parameters > Add Parameter.




回答3:


Is it also possible to get a return value from a subdataset?

It's possible.

In main report you define variable (Integer - is just for example):

<variable name="GLOBAL_VARIABLE" class="java.lang.Integer" resetType="None">
   <initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>

Inside subdataset define another variable.

In datasetRun you can return value from internal variable into global:

<datasetRun subDataset="someDataset" uuid="111">
   <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
   <returnValue fromVariable="SUB_DATASET_VARIABLE" toVariable="GLOBAL_VARIABLE"/>
</datasetRun>

And then just call your variable in main report.

<textField evaluationTime="Report">
<reportElement x="0" y="0" width="200" height="20" uuid="333"/>
<textFieldExpression><![CDATA[$V{GLOBAL_VARIABLE}]]></textFieldExpression>
</textField>

Pay attention to evaluationTime="Report". Without this it will not work.




回答4:


In main report,

<variable name="sum" class="java.lang.Double" resetType="None" calculation="System">
        <initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>

Inside subdataset define another variable. In datasetRun you can return it,

In the main report,

<textField evaluationTime="Now">
                <reportElement x="243" y="12" width="100" height="30" uuid="3b6ae08b-3155-457c-9a27-6ed79b170acb"/>
                <textFieldExpression><![CDATA[$V{sum}]]></textFieldExpression>
</textField>


来源:https://stackoverflow.com/questions/22035080/return-value-from-subdataset-in-ireport

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